aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-modules
diff options
context:
space:
mode:
authorMartin Stockhammer <martin_s@apache.org>2017-10-03 21:52:45 +0200
committerMartin Stockhammer <martin_s@apache.org>2017-10-03 21:52:45 +0200
commit9706f85fdc467310ddef78b4d3269bb0bf582df5 (patch)
tree333932cb2cb96e70c6faf0eb86b28a2c39d7ad7e /archiva-modules
parente0eff36ebc61da1ef90718ecd2bd2bb9e27fb3a8 (diff)
downloadarchiva-9706f85fdc467310ddef78b4d3269bb0bf582df5.tar.gz
archiva-9706f85fdc467310ddef78b4d3269bb0bf582df5.zip
Adding some (imcomplete) changes to the scheduling part
Diffstat (limited to 'archiva-modules')
-rw-r--r--archiva-modules/archiva-base/archiva-repository-layer/pom.xml5
-rw-r--r--archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/ScheduleDefinition.java168
-rw-r--r--archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRepositoryProvider.java21
3 files changed, 189 insertions, 5 deletions
diff --git a/archiva-modules/archiva-base/archiva-repository-layer/pom.xml b/archiva-modules/archiva-base/archiva-repository-layer/pom.xml
index 2bfb418d6..16df6e459 100644
--- a/archiva-modules/archiva-base/archiva-repository-layer/pom.xml
+++ b/archiva-modules/archiva-base/archiva-repository-layer/pom.xml
@@ -100,6 +100,11 @@
<artifactId>wagon-http-lightweight</artifactId>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>com.cronutils</groupId>
+ <artifactId>cron-utils</artifactId>
+ <version>6.0.2</version>
+ </dependency>
</dependencies>
<build>
<plugins>
diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/ScheduleDefinition.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/ScheduleDefinition.java
index 276454464..3084bbc98 100644
--- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/ScheduleDefinition.java
+++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/ScheduleDefinition.java
@@ -20,11 +20,33 @@ package org.apache.archiva.repository;
*/
+import com.cronutils.model.Cron;
+import com.cronutils.model.definition.CronDefinition;
+import com.cronutils.model.definition.CronDefinitionBuilder;
+import com.cronutils.model.field.CronFieldName;
+import com.cronutils.model.field.expression.Always;
+import com.cronutils.model.field.expression.And;
+import com.cronutils.model.field.expression.Between;
+import com.cronutils.model.field.expression.Every;
+import com.cronutils.model.field.expression.FieldExpression;
+import com.cronutils.model.field.expression.On;
+import com.cronutils.model.field.expression.QuestionMark;
+import com.cronutils.model.field.expression.visitor.FieldExpressionVisitor;
+import com.cronutils.model.field.value.IntegerFieldValue;
+import com.cronutils.parser.CronParser;
+import org.apache.tools.ant.types.resources.Sort;
+
import java.time.*;
import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
+import static com.cronutils.model.CronType.QUARTZ;
+
/**
* A definition of schedule times.
*/
@@ -35,6 +57,8 @@ public class ScheduleDefinition {
final SortedSet<MonthDay> daysOfMonth = new TreeSet<>();
+ final SortedSet<Month> months = new TreeSet<>( );
+
final SortedSet<LocalTime> scheduleTimes = new TreeSet<>();
final LocalTime startTime;
@@ -43,19 +67,30 @@ public class ScheduleDefinition {
boolean fixedTimes = false;
-
public ScheduleDefinition(Collection<DayOfWeek> daysOfWeek,
Collection<MonthDay> daysOfMonth,
+ Collection<Month> months,
Collection<LocalTime> scheduleTimes,
LocalTime startTime, Duration timeInterval) {
if (daysOfWeek!=null)
this.daysOfWeek.addAll(daysOfWeek);
if (daysOfMonth!=null)
this.daysOfMonth.addAll(daysOfMonth);
- if (scheduleTimes!=null)
- this.scheduleTimes.addAll(scheduleTimes);
- this.startTime = startTime;
- this.timeInterval = timeInterval;
+ if (months!=null) {
+ this.months.addAll(months);
+ }
+ if (scheduleTimes!=null && scheduleTimes.size()>0)
+ {
+ this.fixedTimes = true;
+ this.scheduleTimes.addAll( scheduleTimes );
+ this.startTime=null;
+ this.timeInterval=null;
+ } else
+ {
+ this.fixedTimes = false;
+ this.startTime = startTime;
+ this.timeInterval = timeInterval;
+ }
}
/**
@@ -75,6 +110,14 @@ public class ScheduleDefinition {
}
/**
+ * Returns the months on which the action should be run.
+ * @return
+ */
+ public SortedSet<Month> getMonths() {
+ return months;
+ }
+
+ /**
* Returns the time on each day on which the action should be run.
* @return a set of times on which the action should be run.
*/
@@ -106,4 +149,119 @@ public class ScheduleDefinition {
public boolean isFixedTimes() {
return fixedTimes;
};
+
+ public static ScheduleDefinition fromCronExpression(String cron) {
+ CronDefinition cronDefinition = CronDefinitionBuilder.instanceDefinitionFor( QUARTZ );
+ CronParser parser = new CronParser( cronDefinition );
+ Cron pCron = parser.parse(cron);
+ if (pCron.validate()==null) {
+ throw new IllegalArgumentException( "Cron expression not valid "+cron );
+ };
+ CronVisitor secondsVisit = new CronVisitor( );
+ pCron.retrieve( CronFieldName.SECOND ).getExpression().accept(secondsVisit);
+ CronVisitor minutesVisit = new CronVisitor( );
+ pCron.retrieve( CronFieldName.MINUTE ).getExpression().accept(minutesVisit);
+ CronVisitor hoursVisit = new CronVisitor( 24 );
+ pCron.retrieve( CronFieldName.HOUR ).getExpression().accept(hoursVisit);
+ SortedSet<LocalTime> times = new TreeSet<>( );
+ for (Integer hour : hoursVisit.getTimes()) {
+ for (Integer minute : minutesVisit.getTimes()) {
+ for (Integer second : secondsVisit.getTimes()) {
+ times.add(LocalTime.of( hour, minute, second));
+ }
+ }
+ }
+
+ return null;
+ }
+
+ private static class CronVisitor implements FieldExpressionVisitor {
+
+ private int range = 60;
+ private SortedSet<Integer> times = new TreeSet<>( );
+
+ CronVisitor() {
+
+ }
+
+ CronVisitor(int range) {
+ this.range = range;
+ }
+
+ private SortedSet<Integer> getTimes() {
+ return times;
+ }
+
+ @Override
+ public FieldExpression visit( FieldExpression expression )
+ {
+ try {
+ Integer in = new Integer(expression.asString());
+ times.add(in);
+ } catch (NumberFormatException ex) {
+ //
+ }
+ return expression;
+ }
+
+ @Override
+ public FieldExpression visit( Always always )
+ {
+ for (int i=0; i<range; i++) {
+ times.add(new Integer(i));
+ }
+ return always;
+ }
+
+ @Override
+ public FieldExpression visit( And and )
+ {
+ FieldExpression result = null;
+ for (FieldExpression expr : and.getExpressions()) {
+ result = expr.accept( this );
+ }
+ return result;
+ }
+
+ @Override
+ public FieldExpression visit( Between between )
+ {
+ for (int i=((IntegerFieldValue) between.getFrom( ).getValue( )).getValue();
+ i<((IntegerFieldValue)between.getTo().getValue()).getValue() && i<range; i++ ){
+ times.add(new Integer(i));
+ }
+ return between;
+ }
+
+ @Override
+ public FieldExpression visit( Every every )
+ {
+ String exp = every.getExpression().asString();
+ int start;
+ if ("*".equals(exp)) {
+ start = 0;
+ } else {
+ start = Integer.parseInt( exp );
+ }
+ int period = every.getPeriod().getValue();
+ for (int i=start; i<range; i=i+period) {
+ times.add(new Integer(i));
+ }
+ return every;
+ }
+
+ @Override
+ public FieldExpression visit( On on )
+ {
+ // Ignore
+ return null;
+ }
+
+ @Override
+ public FieldExpression visit( QuestionMark questionMark )
+ {
+ // Ignore
+ return null;
+ }
+ }
}
diff --git a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRepositoryProvider.java b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRepositoryProvider.java
index f2fc67e87..b90a4deb8 100644
--- a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRepositoryProvider.java
+++ b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRepositoryProvider.java
@@ -26,7 +26,11 @@ import org.apache.archiva.repository.RemoteRepository;
import org.apache.archiva.repository.RepositoryProvider;
import org.apache.archiva.repository.RepositoryType;
import org.apache.archiva.repository.features.StagingRepositoryFeature;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.util.HashSet;
import java.util.Set;
@@ -35,6 +39,8 @@ import java.util.Set;
*/
public class MavenRepositoryProvider implements RepositoryProvider
{
+ private static final Logger log = LoggerFactory.getLogger( MavenRepositoryProvider.class );
+
static final Set<RepositoryType> TYPES = new HashSet<>( );
static {
TYPES.add( RepositoryType.MAVEN);
@@ -50,6 +56,21 @@ public class MavenRepositoryProvider implements RepositoryProvider
public ManagedRepository createManagedInstance( ManagedRepositoryConfiguration cfg )
{
MavenManagedRepository repo = new MavenManagedRepository(cfg.getId() ,cfg.getName());
+ try
+ {
+ if (cfg.getLocation().startsWith("file:")) {
+ repo.setLocation( new URI(cfg.getLocation()) );
+ } else {
+ repo.setLocation( new URI("file://"+cfg.getLocation()) );
+ }
+ }
+ catch ( URISyntaxException e )
+ {
+ log.error("Could not set repository uri "+cfg.getLocation());
+ }
+ cfg.getRefreshCronExpression()
+
+
StagingRepositoryFeature feature = repo.getFeature( StagingRepositoryFeature.class ).get();
return null;
}