From 801f855c2ab215c3bb45f1dfd5ed289d6da1acfe Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Sat, 23 Nov 2019 21:55:31 +0100 Subject: [PATCH] Deactivating repo after move to archiva-components --- Jenkinsfile | 20 - README.md | 6 + pom.xml | 100 ---- .../components/scheduler/AbstractJob.java | 112 ----- .../scheduler/CronExpressionValidator.java | 447 ------------------ .../scheduler/DefaultJobListener.java | 87 ---- .../scheduler/DefaultScheduler.java | 187 -------- .../components/scheduler/Scheduler.java | 60 --- .../configuration/SchedulerConfiguration.java | 129 ----- .../resources/META-INF/spring-context.xml | 34 -- src/site/site.xml | 34 -- .../CronExpressionValidatorTest.java | 131 ----- .../redback/components/scheduler/JobOne.java | 48 -- .../components/scheduler/SchedulerTest.java | 124 ----- src/test/resources/spring-context.xml | 38 -- 15 files changed, 6 insertions(+), 1551 deletions(-) delete mode 100644 Jenkinsfile create mode 100644 README.md delete mode 100644 pom.xml delete mode 100644 src/main/java/org/apache/archiva/redback/components/scheduler/AbstractJob.java delete mode 100644 src/main/java/org/apache/archiva/redback/components/scheduler/CronExpressionValidator.java delete mode 100644 src/main/java/org/apache/archiva/redback/components/scheduler/DefaultJobListener.java delete mode 100644 src/main/java/org/apache/archiva/redback/components/scheduler/DefaultScheduler.java delete mode 100644 src/main/java/org/apache/archiva/redback/components/scheduler/Scheduler.java delete mode 100644 src/main/java/org/apache/archiva/redback/components/scheduler/configuration/SchedulerConfiguration.java delete mode 100755 src/main/resources/META-INF/spring-context.xml delete mode 100644 src/site/site.xml delete mode 100644 src/test/java/org/apache/archiva/redback/components/scheduler/CronExpressionValidatorTest.java delete mode 100644 src/test/java/org/apache/archiva/redback/components/scheduler/JobOne.java delete mode 100644 src/test/java/org/apache/archiva/redback/components/scheduler/SchedulerTest.java delete mode 100755 src/test/resources/spring-context.xml diff --git a/Jenkinsfile b/Jenkinsfile deleted file mode 100644 index 5f264a1..0000000 --- a/Jenkinsfile +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -asfStandardBuild() diff --git a/README.md b/README.md new file mode 100644 index 0000000..3791229 --- /dev/null +++ b/README.md @@ -0,0 +1,6 @@ +This project has been moved to +org.apache.archiva.components.archiva-components-spring-quartz + +Git: +https://gitbox.apache.org/repos/asf/archiva-components.git + diff --git a/pom.xml b/pom.xml deleted file mode 100644 index 14a34b3..0000000 --- a/pom.xml +++ /dev/null @@ -1,100 +0,0 @@ - - - - - 4.0.0 - - - org.apache.archiva.redback.components - redback-components - 2.5-SNAPSHOT - - - 2.2-SNAPSHOT - spring-quartz - - Spring Quartz Component - - - https://gitbox.apache.org/repos/asf?a=tree;p=archiva-redback-components-spring-quartz.git - ${project.basedir}/../site - - - - ${webUrl}/${project.artifactId} - - - scm:git:http://gitbox.apache.org/repos/asf/archiva-redback-components-spring-quartz.git - scm:git:https://gitbox.apache.org/repos/asf/archiva-redback-components-spring-quartz.git - ${scmBrowseUrl};f=spring-quartz - - - - - javax.inject - javax.inject - - - javax.annotation - javax.annotation-api - - - org.springframework - spring-context - - - org.quartz-scheduler - quartz - 2.2.1 - - - c3p0 - c3p0 - - - - - org.slf4j - slf4j-api - - - commons-lang - commons-lang - - - org.springframework - spring-test - test - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - - 60 - - - - - - diff --git a/src/main/java/org/apache/archiva/redback/components/scheduler/AbstractJob.java b/src/main/java/org/apache/archiva/redback/components/scheduler/AbstractJob.java deleted file mode 100644 index c89e795..0000000 --- a/src/main/java/org/apache/archiva/redback/components/scheduler/AbstractJob.java +++ /dev/null @@ -1,112 +0,0 @@ -package org.apache.archiva.redback.components.scheduler; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.quartz.JobDataMap; -import org.quartz.JobExecutionContext; -import org.quartz.JobExecutionException; -import org.quartz.InterruptableJob; -import org.quartz.UnableToInterruptJobException; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Base class from which all Jobs running in the - * scheduler should be derived from if they want access to the - * ServiceBroker. - * - * @author Jason van Zyl - */ -public abstract class AbstractJob - implements InterruptableJob -{ - - private Logger log = LoggerFactory.getLogger( getClass() ); - - /** - * JobDataMap tag for the job's logger. - */ - public static final String LOGGER = "JOB_LOGGER"; - - /** - * JobDataMap tag for the job's context. - */ - public static final String CONTEXT = "JOB_CONTEXT"; - - /** - * JobDataMap tag for the job's service broker. - */ - public static final String SERVICE_MANAGER = "JOB_SERVICE_MANAGER"; - - /** - * JobDataMap tag for the job's configuration. - */ - public static final String EXECUTION_CONFIGURATION = "JOB_EXECUTION_CONFIGURATION"; - - /** - * Job Data Map - */ - private JobDataMap jobDataMap; - - private boolean interrupted; - - /** - * Set Job Data Map - */ - public void setJobDataMap( JobDataMap jobDataMap ) - { - this.jobDataMap = jobDataMap; - } - - /** - * Get Job Data Map - */ - public JobDataMap getJobDataMap() - { - return jobDataMap; - } - - /** - * Get the Logger. - */ - public Logger getLogger() - { - return (Logger) getJobDataMap().get( LOGGER ); - } - - - /** - * Execute the Job. - */ - public abstract void execute( JobExecutionContext context ) - throws JobExecutionException; - - public boolean isInterrupted() - { - return interrupted; - } - - public void interrupt() - throws UnableToInterruptJobException - { - interrupted = true; - } -} diff --git a/src/main/java/org/apache/archiva/redback/components/scheduler/CronExpressionValidator.java b/src/main/java/org/apache/archiva/redback/components/scheduler/CronExpressionValidator.java deleted file mode 100644 index 54bbe41..0000000 --- a/src/main/java/org/apache/archiva/redback/components/scheduler/CronExpressionValidator.java +++ /dev/null @@ -1,447 +0,0 @@ -package org.apache.archiva.redback.components.scheduler; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.commons.lang.StringUtils; -import org.quartz.CronScheduleBuilder; -import org.quartz.CronTrigger; -import org.quartz.TriggerBuilder; -import org.springframework.stereotype.Service; - -import java.text.ParseException; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.StringTokenizer; - -/** - * @author Emmanuel Venisse - * - */ -@Service -public final class CronExpressionValidator -{ - - /** - * Validates a cron expression. - * - * @param cronExpression The expression to validate - * @return True is expression is valid - */ - public boolean validate( String cronExpression ) - { - try - { - String[] cronParams = StringUtils.split( cronExpression ); - - if ( cronParams.length < 6 || cronParams.length > 7 ) - { - return false; - } - - CronTrigger cronTrigger = TriggerBuilder.newTrigger() - .withSchedule( CronScheduleBuilder.cronSchedule( cronExpression ) ) - .build(); - - - - if ( cronParams[3].equals( "?" ) || cronParams[5].equals( "?" ) ) - { - //Check seconds param - if ( !checkSecondsField( cronParams[0] ) ) - { - return false; - } - - //Check minutes param - if ( !checkMinutesField( cronParams[1] ) ) - { - return false; - } - - //Check hours param - if ( !checkHoursField( cronParams[2] ) ) - { - return false; - } - - //Check day-of-month param - if ( !checkDayOfMonthField( cronParams[3] ) ) - { - return false; - } - - //Check months param - if ( !checkMonthsField( cronParams[4] ) ) - { - return false; - } - - //Check day-of-week param - if ( !checkDayOfWeekField( cronParams[5] ) ) - { - return false; - } - - //Check year param - if ( cronParams.length == 7 ) - { - if ( !checkYearField( cronParams[6] ) ) - { - return false; - } - } - - return true; - } - else - { - return false; - } - } - catch ( RuntimeException e ) - { - return false; - } - } - - private boolean checkSecondsField( String secondsField ) - { - return checkField( secondsField, 0, 59 ); - } - - private boolean checkMinutesField( String minutesField ) - { - return checkField( minutesField, 0, 59 ); - } - - private boolean checkHoursField( String hoursField ) - { - return checkField( hoursField, 0, 23 ); - } - - private boolean checkDayOfMonthField( String dayOfMonthField ) - { - if ( "?".equals( dayOfMonthField ) ) - { - return true; - } - - if ( dayOfMonthField.indexOf( 'L' ) >= 0 ) - { - return checkFieldWithLetter( dayOfMonthField, "L", 1, 7, -1, -1 ); - } - else if ( dayOfMonthField.indexOf( 'W' ) >= 0 ) - { - return checkFieldWithLetter( dayOfMonthField, "W", 1, 31, -1, -1 ); - } - else if ( dayOfMonthField.indexOf( 'C' ) >= 0 ) - { - return checkFieldWithLetter( dayOfMonthField, "C", 1, 31, -1, -1 ); - } - else - { - return checkField( dayOfMonthField, 1, 31 ); - } - } - - private boolean checkMonthsField( String monthsField ) - { - monthsField = StringUtils.replace( monthsField, "JAN", "1" ); - monthsField = StringUtils.replace( monthsField, "FEB", "2" ); - monthsField = StringUtils.replace( monthsField, "MAR", "3" ); - monthsField = StringUtils.replace( monthsField, "APR", "4" ); - monthsField = StringUtils.replace( monthsField, "MAY", "5" ); - monthsField = StringUtils.replace( monthsField, "JUN", "6" ); - monthsField = StringUtils.replace( monthsField, "JUL", "7" ); - monthsField = StringUtils.replace( monthsField, "AUG", "8" ); - monthsField = StringUtils.replace( monthsField, "SEP", "9" ); - monthsField = StringUtils.replace( monthsField, "OCT", "10" ); - monthsField = StringUtils.replace( monthsField, "NOV", "11" ); - monthsField = StringUtils.replace( monthsField, "DEC", "12" ); - - return checkField( monthsField, 1, 31 ); - } - - private boolean checkDayOfWeekField( String dayOfWeekField ) - { - dayOfWeekField = StringUtils.replace( dayOfWeekField, "SUN", "1" ); - dayOfWeekField = StringUtils.replace( dayOfWeekField, "MON", "2" ); - dayOfWeekField = StringUtils.replace( dayOfWeekField, "TUE", "3" ); - dayOfWeekField = StringUtils.replace( dayOfWeekField, "WED", "4" ); - dayOfWeekField = StringUtils.replace( dayOfWeekField, "THU", "5" ); - dayOfWeekField = StringUtils.replace( dayOfWeekField, "FRI", "6" ); - dayOfWeekField = StringUtils.replace( dayOfWeekField, "SAT", "7" ); - - if ( "?".equals( dayOfWeekField ) ) - { - return true; - } - - if ( dayOfWeekField.indexOf( 'L' ) >= 0 ) - { - return checkFieldWithLetter( dayOfWeekField, "L", 1, 7, -1, -1 ); - } - else if ( dayOfWeekField.indexOf( 'C' ) >= 0 ) - { - return checkFieldWithLetter( dayOfWeekField, "C", 1, 7, -1, -1 ); - } - else if ( dayOfWeekField.indexOf( '#' ) >= 0 ) - { - return checkFieldWithLetter( dayOfWeekField, "#", 1, 7, 1, 5 ); - } - else - { - return checkField( dayOfWeekField, 1, 7 ); - } - } - - private boolean checkYearField( String yearField ) - { - return checkField( yearField, 1970, 2099 ); - } - - private boolean checkField( String secondsField, int minimal, int maximal ) - { - if ( secondsField.indexOf( '-' ) > -1 ) - { - String startValue = secondsField.substring( 0, secondsField.indexOf( "-" ) ); - String endValue = secondsField.substring( secondsField.indexOf( "-" ) + 1 ); - - if ( !( checkIntValue( startValue, minimal, maximal ) && checkIntValue( endValue, minimal, maximal ) ) ) - { - return false; - } - try - { - int startVal = Integer.parseInt( startValue ); - int endVal = Integer.parseInt( endValue ); - - return endVal > startVal; - - } - catch ( NumberFormatException e ) - { - return false; - } - } - else if ( secondsField.indexOf( ',' ) > -1 ) - { - return checkListField( secondsField, minimal, maximal ); - } - else if ( secondsField.indexOf( '/' ) > -1 ) - { - return checkIncrementField( secondsField, minimal, maximal ); - } - else if ( secondsField.indexOf( '*' ) != -1 ) - { - return true; - } - else - { - return checkIntValue( secondsField, minimal, maximal ); - } - } - - private boolean checkFieldWithLetter( String value, String letter, int minimalBefore, int maximalBefore, - int minimalAfter, int maximalAfter ) - { - boolean canBeAlone = false; - boolean canHaveIntBefore = false; - boolean canHaveIntAfter = false; - boolean mustHaveIntBefore = false; - boolean mustHaveIntAfter = false; - - if ( "L".equals( letter ) ) - { - canBeAlone = true; - canHaveIntBefore = true; - canHaveIntAfter = false; - mustHaveIntBefore = false; - mustHaveIntAfter = false; - } - if ( "W".equals( letter ) || "C".equals( letter ) ) - { - canBeAlone = false; - canHaveIntBefore = true; - canHaveIntAfter = false; - mustHaveIntBefore = true; - mustHaveIntAfter = false; - } - if ( "#".equals( letter ) ) - { - canBeAlone = false; - canHaveIntBefore = true; - canHaveIntAfter = true; - mustHaveIntBefore = true; - mustHaveIntAfter = true; - } - - String beforeLetter = ""; - String afterLetter = ""; - - if ( value.indexOf( letter ) >= 0 ) - { - beforeLetter = value.substring( 0, value.indexOf( letter ) ); - } - - if ( !value.endsWith( letter ) ) - { - afterLetter = value.substring( value.indexOf( letter ) + 1 ); - } - - if ( value.indexOf( letter ) >= 0 ) - { - if ( letter.equals( value ) ) - { - return canBeAlone; - } - - if ( canHaveIntBefore ) - { - if ( mustHaveIntBefore && beforeLetter.length() == 0 ) - { - return false; - } - - if ( !checkIntValue( beforeLetter, minimalBefore, maximalBefore, true ) ) - { - return false; - } - } - else - { - if ( beforeLetter.length() > 0 ) - { - return false; - } - } - - if ( canHaveIntAfter ) - { - if ( mustHaveIntAfter && afterLetter.length() == 0 ) - { - return false; - } - - if ( !checkIntValue( afterLetter, minimalAfter, maximalAfter, true ) ) - { - return false; - } - } - else - { - if ( afterLetter.length() > 0 ) - { - return false; - } - } - } - - return true; - } - - private boolean checkIncrementField( String value, int minimal, int maximal ) - { - String start = value.substring( 0, value.indexOf( '/' ) ); - - String increment = value.substring( value.indexOf( '/' ) + 1 ); - - if ( !"*".equals( start ) ) - { - return checkIntValue( start, minimal, maximal ) && checkIntValue( increment, minimal, maximal, false ); - } - else - { - return checkIntValue( increment, minimal, maximal ); - } - } - - private boolean checkListField( String value, int minimal, int maximal ) - { - StringTokenizer st = new StringTokenizer( value, "," ); - - List values = new ArrayList<>(); - - while ( st.hasMoreTokens() ) - { - values.add( st.nextToken() ); - } - - int previousValue = -1; - - for ( Iterator i = values.iterator(); i.hasNext(); ) - { - String currentValue = i.next(); - - if ( !checkIntValue( currentValue, minimal, maximal ) ) - { - return false; - } - - try - { - int val = Integer.parseInt( currentValue ); - - if ( val <= previousValue ) - { - return false; - } - else - { - previousValue = val; - } - } - catch ( NumberFormatException e ) - { - // we have always an int - } - } - - return true; - } - - private boolean checkIntValue( String value, int minimal, int maximal ) - { - return checkIntValue( value, minimal, maximal, true ); - } - - private static boolean checkIntValue( String value, int minimal, int maximal, boolean checkExtremity ) - { - try - { - int val = Integer.parseInt( value ); - - if ( checkExtremity ) - { - if ( val < minimal || val > maximal ) - { - return false; - } - } - - return true; - } - catch ( NumberFormatException e ) - { - return false; - } - } -} diff --git a/src/main/java/org/apache/archiva/redback/components/scheduler/DefaultJobListener.java b/src/main/java/org/apache/archiva/redback/components/scheduler/DefaultJobListener.java deleted file mode 100644 index 21d9c4a..0000000 --- a/src/main/java/org/apache/archiva/redback/components/scheduler/DefaultJobListener.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.apache.archiva.redback.components.scheduler; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -import org.quartz.Job; -import org.quartz.JobExecutionContext; -import org.quartz.JobExecutionException; -import org.quartz.JobListener; - -/** - * Currently the role this class plays is set the value of the JobDataMap - * in the job so that the convenience methods for accessing the logger, context, - * service broker and configuration will work as expected. - * - * @author Jason van Zyl - * - */ -public class DefaultJobListener - implements JobListener -{ - /** - *

- *

- * Get the name of the JobListener.

- */ - public String getName() - { - return "DefaultJobLister"; - } - - /** - *

- *

- * Called by the {@link Scheduler} when a {@link Job} - * is about to be executed (an associated {@link org.quartz.Trigger} has - * occured).

- */ - public void jobToBeExecuted( JobExecutionContext context ) - { - Job job = context.getJobInstance(); - - // Only attempt to set the ServiceBroker when we are dealing - // with subclasses AbstractJob. - if ( job instanceof AbstractJob ) - { - ( (AbstractJob) job ).setJobDataMap( context.getJobDetail().getJobDataMap() ); - } - } - - public void jobExecutionVetoed( JobExecutionContext jobExecutionContext ) - { - } - - /** - *

- *

- * Called by the {@link Scheduler} after a {@link Job} - * has been executed, and be for the associated Trigger's - * triggered(xx) method has been called.

- */ - public void jobWasExecuted( JobExecutionContext context, JobExecutionException jobException ) - { - Job job = context.getJobInstance(); - - // Only attempt to null the ServiceBroker when we are dealing - // with subclasses AbstractJob. - if ( job instanceof AbstractJob ) - { - } - } -} diff --git a/src/main/java/org/apache/archiva/redback/components/scheduler/DefaultScheduler.java b/src/main/java/org/apache/archiva/redback/components/scheduler/DefaultScheduler.java deleted file mode 100644 index 55f912b..0000000 --- a/src/main/java/org/apache/archiva/redback/components/scheduler/DefaultScheduler.java +++ /dev/null @@ -1,187 +0,0 @@ -package org.apache.archiva.redback.components.scheduler; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.quartz.JobDetail; -import org.quartz.JobKey; -import org.quartz.JobListener; -import org.quartz.Matcher; -import org.quartz.SchedulerException; -import org.quartz.SchedulerFactory; -import org.quartz.Trigger; -import org.quartz.TriggerListener; -import org.quartz.impl.StdScheduler; -import org.quartz.impl.StdSchedulerFactory; -import org.quartz.utils.Key; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; -import java.util.Properties; - -public class DefaultScheduler - implements Scheduler -{ - - private Logger log = LoggerFactory.getLogger( getClass() ); - - private Properties properties; - - private StdScheduler scheduler; - - public void scheduleJob( JobDetail jobDetail, Trigger trigger ) - throws SchedulerException - { - - if ( jobDetail == null || jobDetail.getKey() == null || jobDetail.getKey().getName() == null ) - { - throw new SchedulerException( "No job or no job name - cannot schedule this job" ); - } - - if ( jobExists( jobDetail.getKey() ) ) - { - log.warn( "Will not schedule this job as a job ({}:{}) already exists.", - jobDetail.getKey().getName(), jobDetail.getKey().getGroup() ); - - return; - } - - try - { - scheduler.scheduleJob( jobDetail, trigger ); - } - catch ( SchedulerException e ) - { - throw new SchedulerException( "Error scheduling job.", e ); - } - catch ( Exception e ) - { - throw new SchedulerException( "Error scheduling job (Verify your cron expression).", e ); - } - } - - public void addGlobalJobListener( JobListener listener ) - throws SchedulerException - { - scheduler.getListenerManager().addJobListener( listener, new AllMatch() ); - } - - public void addGlobalTriggerListener( TriggerListener listener ) - throws SchedulerException - { - scheduler.getListenerManager().addTriggerListener( listener, new AllMatch() ); - } - - private static class AllMatch> - implements Matcher - { - public boolean isMatch( R key ) - { - return true; - } - } - - @PostConstruct - public void initialize() - throws SchedulerException - { - SchedulerFactory factory = new StdSchedulerFactory( properties ); - - scheduler = (StdScheduler) factory.getScheduler(); - - scheduler.start(); - - } - - @PreDestroy - public void stop() - { - scheduler.shutdown(); - } - - public void unscheduleJob( String jobName, String groupName ) - throws SchedulerException - { - if ( jobName == null ) - { - throw new SchedulerException( "Job name null - cannot unschedule job" ); - } - - try - { - if ( jobExists( jobName, groupName ) ) - { - scheduler.deleteJob( new JobKey( jobName, groupName ) ); - } - } - catch ( SchedulerException e ) - { - throw new SchedulerException( "Error unscheduling job.", e ); - } - } - - public boolean interruptSchedule( String jobName, String groupName ) - throws SchedulerException - { - try - { - return scheduler.interrupt( new JobKey( jobName, groupName ) ); - } - catch ( Exception e ) - { - throw new SchedulerException( "Can't interrup job \"" + jobName + "\".", e ); - } - } - - private boolean jobExists( String jobName, String jobGroup ) - throws SchedulerException - { - - return jobExists( new JobKey( jobName, jobGroup ) ); - } - - private boolean jobExists( JobKey jobKey ) - throws SchedulerException - { - return scheduler.getJobDetail( jobKey ) != null; - } - - public void shutdown( boolean waitForJobsToComplete ) - { - log.info( "call shutdown waitForJobsToComplete : {}", waitForJobsToComplete ); - scheduler.shutdown( waitForJobsToComplete ); - } - - public StdScheduler getScheduler() - { - return scheduler; - } - - public void setProperties( Properties properties ) - { - this.properties = properties; - } - - public Properties getProperties() - { - return properties; - } -} diff --git a/src/main/java/org/apache/archiva/redback/components/scheduler/Scheduler.java b/src/main/java/org/apache/archiva/redback/components/scheduler/Scheduler.java deleted file mode 100644 index d64e24f..0000000 --- a/src/main/java/org/apache/archiva/redback/components/scheduler/Scheduler.java +++ /dev/null @@ -1,60 +0,0 @@ -package org.apache.archiva.redback.components.scheduler; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.quartz.JobDetail; -import org.quartz.JobListener; -import org.quartz.SchedulerException; -import org.quartz.Trigger; -import org.quartz.TriggerListener; - -import java.util.Properties; - -public interface Scheduler -{ - - void scheduleJob( JobDetail jobDetail, Trigger trigger ) - throws SchedulerException; - - /** - * @param listener - */ - void addGlobalJobListener( JobListener listener ) - throws SchedulerException; - - /** - * @param listener - */ - void addGlobalTriggerListener( TriggerListener listener ) - throws SchedulerException; - - void unscheduleJob( String jobName, String groupName ) - throws SchedulerException; - - boolean interruptSchedule( String jobName, String groupName ) - throws SchedulerException; - - void setProperties( Properties properties ); - - Properties getProperties(); - - void shutdown( boolean waitForJobsToComplete ); - -} diff --git a/src/main/java/org/apache/archiva/redback/components/scheduler/configuration/SchedulerConfiguration.java b/src/main/java/org/apache/archiva/redback/components/scheduler/configuration/SchedulerConfiguration.java deleted file mode 100644 index 00e7131..0000000 --- a/src/main/java/org/apache/archiva/redback/components/scheduler/configuration/SchedulerConfiguration.java +++ /dev/null @@ -1,129 +0,0 @@ -package org.apache.archiva.redback.components.scheduler.configuration; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.archiva.redback.components.scheduler.Scheduler; -import org.quartz.impl.StdSchedulerFactory; -import org.springframework.stereotype.Service; - -import javax.inject.Inject; - -/** - * Class to represent the configuration file for the proxy - * - * @author John Tolentino - */ -@Service -public class SchedulerConfiguration -{ - @Inject - private Scheduler scheduler; - - public String getInstanceName() - { - return scheduler.getProperties().getProperty( StdSchedulerFactory.PROP_SCHED_INSTANCE_NAME ); - } - - public void setInstanceName( String instanceName ) - { - scheduler.getProperties().setProperty( StdSchedulerFactory.PROP_SCHED_INSTANCE_NAME, instanceName ); - } - - public String getInstanceId() - { - return scheduler.getProperties().getProperty( StdSchedulerFactory.PROP_SCHED_INSTANCE_ID ); - } - - public void setInstanceId( String InstanceId ) - { - scheduler.getProperties().setProperty( StdSchedulerFactory.PROP_SCHED_INSTANCE_ID, InstanceId ); - } - - public String getThreadName() - { - return scheduler.getProperties().getProperty( StdSchedulerFactory.PROP_SCHED_THREAD_NAME ); - } - - public void setThreadName( String threadName ) - { - scheduler.getProperties().setProperty( StdSchedulerFactory.PROP_SCHED_THREAD_NAME, threadName ); - } - - public String getIdleWaitTime() - { - return scheduler.getProperties().getProperty( StdSchedulerFactory.PROP_SCHED_IDLE_WAIT_TIME ); - } - - public void setIdleWaitTime( String idleWaitTime ) - { - scheduler.getProperties().setProperty( StdSchedulerFactory.PROP_SCHED_IDLE_WAIT_TIME, idleWaitTime ); - } - - public String getDbFailureRetryInterval() - { - return scheduler.getProperties().getProperty( StdSchedulerFactory.PROP_SCHED_DB_FAILURE_RETRY_INTERVAL ); - } - - public void setDbFailureRetryInterval( String dbFailureRetryInterval ) - { - scheduler.getProperties().setProperty( StdSchedulerFactory.PROP_SCHED_DB_FAILURE_RETRY_INTERVAL, dbFailureRetryInterval ); - } - - public String getClassLoadHelper() - { - return scheduler.getProperties().getProperty( StdSchedulerFactory.PROP_SCHED_CLASS_LOAD_HELPER_CLASS ); - } - - public void setClassLoadHelper( String classLoadHelper ) - { - scheduler.getProperties().setProperty( StdSchedulerFactory.PROP_SCHED_CLASS_LOAD_HELPER_CLASS, classLoadHelper ); - } - - public String getContextKey() - { - return scheduler.getProperties().getProperty( StdSchedulerFactory.PROP_SCHED_CONTEXT_PREFIX ); - } - - public void setContextKey( String contextKey ) - { - scheduler.getProperties().setProperty( StdSchedulerFactory.PROP_SCHED_CONTEXT_PREFIX, contextKey ); - } - - public String getUserTransactionURL() - { - return scheduler.getProperties().getProperty( StdSchedulerFactory.PROP_SCHED_USER_TX_URL ); - } - - public void setUserTransactionURL( String userTransactionURL ) - { - scheduler.getProperties().setProperty( StdSchedulerFactory.PROP_SCHED_USER_TX_URL, userTransactionURL ); - } - - public String getWrapJobExecutionInUserTransaction() - { - return scheduler.getProperties().getProperty( StdSchedulerFactory.PROP_SCHED_WRAP_JOB_IN_USER_TX ); - } - - public void setWrapJobExecutionInUserTransaction( String wrapJobExecutionInUserTransaction ) - { - scheduler.getProperties().setProperty( StdSchedulerFactory.PROP_SCHED_WRAP_JOB_IN_USER_TX, wrapJobExecutionInUserTransaction ); - } - -} diff --git a/src/main/resources/META-INF/spring-context.xml b/src/main/resources/META-INF/spring-context.xml deleted file mode 100755 index cff1130..0000000 --- a/src/main/resources/META-INF/spring-context.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/src/site/site.xml b/src/site/site.xml deleted file mode 100644 index b69f3ec..0000000 --- a/src/site/site.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - - - - - - - - - diff --git a/src/test/java/org/apache/archiva/redback/components/scheduler/CronExpressionValidatorTest.java b/src/test/java/org/apache/archiva/redback/components/scheduler/CronExpressionValidatorTest.java deleted file mode 100644 index 79b1738..0000000 --- a/src/test/java/org/apache/archiva/redback/components/scheduler/CronExpressionValidatorTest.java +++ /dev/null @@ -1,131 +0,0 @@ -package org.apache.archiva.redback.components.scheduler; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import junit.framework.TestCase; -import org.apache.archiva.redback.components.scheduler.CronExpressionValidator; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import javax.inject.Inject; - -@RunWith( SpringJUnit4ClassRunner.class ) -@ContextConfiguration( locations = {"classpath*:/META-INF/spring-context.xml","classpath:/spring-context.xml"} ) -public class CronExpressionValidatorTest - extends TestCase -{ - - @Inject - CronExpressionValidator validator; - - @Test - public void testValidation() - throws Exception - { - - assertTrue( validator.validate( "0 0 * * * ?" ) ); - - assertTrue( validator.validate( "0 0 * ? * *" ) ); - - assertFalse( validator.validate( "0 0 4-1 * * ?" ) ); - - assertTrue( validator.validate( "0 0 1-4 * * ?" ) ); - - assertTrue( validator.validate( "0 0,15,30,45 * * * ?" ) ); - - assertFalse( validator.validate( "0 0,45,15,30 * * * ?" ) ); - - assertTrue( validator.validate( "0 0 12 * * ?" ) ); - - assertTrue( validator.validate( "0 15 10 ? * *" ) ); - - assertTrue( validator.validate( "0 15 10 * * ?" ) ); - - assertTrue( validator.validate( "0 15 10 * * ? *" ) ); - - assertTrue( validator.validate( "0 15 10 * * ? 2005" ) ); - - assertFalse( validator.validate( "0 15 10 * * ? 2100" ) ); - - assertFalse( validator.validate( "0 15 10 * * ? 1969" ) ); - - assertTrue( validator.validate( "0 15 10 * * ? 2005-2007" ) ); - - assertFalse( validator.validate( "0 15 10 * * ? 2005-2100" ) ); - - assertFalse( validator.validate( "0 15 10 * * ? 1960-2010" ) ); - - assertTrue( validator.validate( "0 15 10 * * ? 2005/2" ) ); - - assertFalse( validator.validate( "0 15 10 * * ? 2100/3" ) ); - - assertFalse( validator.validate( "0 15 10 * * ? 1960/10" ) ); - - assertTrue( validator.validate( "0 * 14 * * ?" ) ); - - assertTrue( validator.validate( "0 0/5 14 * * ?" ) ); - - assertTrue( validator.validate( "0 0/5 14,18 * * ?" ) ); - - assertTrue( validator.validate( "0 0-5 14 * * ?" ) ); - - assertTrue( validator.validate( "0 10,44 14 ? 3 WED" ) ); - - assertTrue( validator.validate( "0 15 10 ? * MON-FRI" ) ); - - assertTrue( validator.validate( "0 15 10 15 * ?" ) ); - - assertTrue( validator.validate( "0 15 10 L * ?" ) ); - - assertFalse( validator.validate( "0 15 10 6#3 * ?" ) ); - - assertTrue( validator.validate( "0 15 10 15W * ?" ) ); - - assertFalse( validator.validate( "0 15 10 15W1 * ?" ) ); - - assertTrue( validator.validate( "0 15 10 ? * 6L" ) ); - - assertTrue( validator.validate( "0 15 10 ? * 6L" ) ); - - assertTrue( validator.validate( "0 15 10 ? * 6L 2002-2005" ) ); - - assertFalse( validator.validate( "0 15 10 ? * 6L3 2002-2005" ) ); - - assertTrue( validator.validate( "0 15 10 ? * 6#3" ) ); - - assertFalse( validator.validate( "0 15 10 ? * 6#" ) ); - - assertFalse( validator.validate( "0 15 10 ? * #3" ) ); - - assertFalse( validator.validate( "0 15 10 ? * 8#3" ) ); - - assertFalse( validator.validate( "0 15 10 ? * 6#6" ) ); - - assertFalse( validator.validate( "0 0" ) ); - - assertFalse( validator.validate( "0 0 * * * *" ) ); - - assertFalse( validator.validate( "a a a a a a" ) ); - - assertFalse( validator.validate( "0 0 0 ? 0 A" ) ); - } -} diff --git a/src/test/java/org/apache/archiva/redback/components/scheduler/JobOne.java b/src/test/java/org/apache/archiva/redback/components/scheduler/JobOne.java deleted file mode 100644 index 19de8a9..0000000 --- a/src/test/java/org/apache/archiva/redback/components/scheduler/JobOne.java +++ /dev/null @@ -1,48 +0,0 @@ -package org.apache.archiva.redback.components.scheduler; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.quartz.Job; -import org.quartz.JobExecutionContext; -import org.quartz.JobExecutionException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Date; - -public class JobOne - implements Job -{ - - private Logger logger = LoggerFactory.getLogger( getClass() ); - - public JobOne() - { - } - - public void execute( JobExecutionContext context ) - throws JobExecutionException - { - logger.info( - " --- Testing Scheduler Component --- {} executed.[{}]", context.getJobDetail().getDescription(), new Date() ); - - } - -} diff --git a/src/test/java/org/apache/archiva/redback/components/scheduler/SchedulerTest.java b/src/test/java/org/apache/archiva/redback/components/scheduler/SchedulerTest.java deleted file mode 100644 index 0f1b39c..0000000 --- a/src/test/java/org/apache/archiva/redback/components/scheduler/SchedulerTest.java +++ /dev/null @@ -1,124 +0,0 @@ -package org.apache.archiva.redback.components.scheduler; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import junit.framework.TestCase; -import org.junit.After; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.quartz.JobBuilder; -import org.quartz.JobDataMap; -import org.quartz.JobDetail; -import org.quartz.JobExecutionContext; -import org.quartz.Trigger; -import org.quartz.TriggerBuilder; -import org.quartz.TriggerListener; -import org.quartz.impl.triggers.SimpleTriggerImpl; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import javax.inject.Inject; - -@RunWith ( SpringJUnit4ClassRunner.class ) -@ContextConfiguration ( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } ) -public class SchedulerTest - extends TestCase - implements TriggerListener -{ - private boolean triggerFired; - - private Logger logger = LoggerFactory.getLogger( getClass() ); - - @Inject - private Scheduler scheduler; - - @After - public void stop() - { - scheduler.shutdown( true ); - } - - @Test - public void testCreation() - throws Exception - { - - assertNotNull( scheduler ); - - JobDataMap dataMap = new JobDataMap(); - - dataMap.put( "project", "continuum" ); - - JobDetail jobDetail = JobBuilder.newJob( JobOne.class ) - .withIdentity( "job", "group" ) - .setJobData( dataMap ) - .build(); - - TriggerBuilder.newTrigger(); - - Trigger trigger = new SimpleTriggerImpl( "trigger", "group" ); - - scheduler.addGlobalTriggerListener( this ); - - scheduler.scheduleJob( jobDetail, trigger ); - - while ( !triggerFired ) - { - Thread.sleep( 10 ); - } - logger.info( "ok triggerFired" ); - } - - public void triggerComplete( Trigger trigger, JobExecutionContext context, int triggerInstructionCode ) - { - } - - public boolean vetoJobExecution( Trigger trigger, JobExecutionContext context ) - { - return false; - } - - public void triggerFired( Trigger trigger, JobExecutionContext context ) - { - logger.info( "Trigger fired!" ); - - triggerFired = true; - } - - public void triggerMisfired( Trigger trigger ) - { - } - - public void triggerComplete( Trigger trigger, JobExecutionContext context, - Trigger.CompletedExecutionInstruction triggerInstructionCode ) - { - //To change body of implemented methods use File | Settings | File Templates. - } - - public String getName() - { - return "foo"; - } - - -} - diff --git a/src/test/resources/spring-context.xml b/src/test/resources/spring-context.xml deleted file mode 100755 index 26f0515..0000000 --- a/src/test/resources/spring-context.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - scheduler1 - org.quartz.simpl.SimpleThreadPool - 1 - 4 - org.quartz.simpl.RAMJobStore - - - - - \ No newline at end of file