From: Edwin L. Punzalan Date: Thu, 2 Mar 2006 09:53:40 +0000 (+0000) Subject: PR: MRM-36 X-Git-Tag: archiva-0.9-alpha-1~899 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=cbfc5b63db23edde2fbd86ea8a84784068ccedf6;p=archiva.git PR: MRM-36 Submitted by: Maria Odea Ching Applied patch for discovery and indexing schedule git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@382337 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/maven-repository-webapp/pom.xml b/maven-repository-webapp/pom.xml index 92cb24fa0..cef65a3b5 100644 --- a/maven-repository-webapp/pom.xml +++ b/maven-repository-webapp/pom.xml @@ -42,7 +42,7 @@ org.mortbay.jetty maven-jetty6-plugin - ${basedir}/target/${artifactId} + ${basedir}/target/${artifactId} 10 diff --git a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/BaseAction.java b/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/BaseAction.java new file mode 100644 index 000000000..eaedb6342 --- /dev/null +++ b/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/BaseAction.java @@ -0,0 +1,57 @@ +package org.apache.maven.repository.manager.web.action; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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 com.opensymphony.xwork.Action; +import org.apache.maven.repository.manager.web.job.DiscovererScheduler; + +/** + * This is the Action class of index.jsp, which is the initial page of the web application. + * It invokes the DiscovererScheduler to set the DiscoverJob in the scheduler. + * + * @plexus.component role="com.opensymphony.xwork.Action" role-hint="org.apache.maven.repository.manager.web.action.BaseAction" + */ +public class BaseAction + implements Action +{ + + /** + * @plexus.requirement + */ + private DiscovererScheduler discovererScheduler; + + /** + * Method that executes the action + * + * @return a String that specifies if the action executed was a success or a failure + */ + public String execute() + { + try + { + discovererScheduler.setSchedule(); + } + catch ( Exception e ) + { + e.printStackTrace(); + return ERROR; + } + + return SUCCESS; + } + +} diff --git a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/job/Configuration.java b/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/job/Configuration.java index 38940d9f9..c0fe67f79 100644 --- a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/job/Configuration.java +++ b/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/job/Configuration.java @@ -24,7 +24,7 @@ import java.util.Properties; */ /** - * + * This class contains the configuration values to be used by the scheduler */ public class Configuration implements Initializable @@ -32,17 +32,29 @@ public class Configuration private Properties props; + /** + * @throws InitializationException + */ public void initialize() throws InitializationException { - System.out.println( "Configuration initialized" ); } + /** + * Set the properties object + * + * @param properties + */ public void setProperties( Properties properties ) { this.props = properties; } + /** + * Returns the properties object + * + * @return a Properties object that contains the configuration values + */ public Properties getProperties() { return props; diff --git a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/job/DiscovererJob.java b/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/job/DiscovererJob.java new file mode 100644 index 000000000..fd05700c3 --- /dev/null +++ b/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/job/DiscovererJob.java @@ -0,0 +1,260 @@ +package org.apache.maven.repository.manager.web.job; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.maven.artifact.Artifact; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; +import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; +import org.apache.maven.artifact.repository.metadata.RepositoryMetadata; +import org.apache.maven.model.Model; +import org.apache.maven.repository.discovery.ArtifactDiscoverer; +import org.apache.maven.repository.discovery.DefaultArtifactDiscoverer; +import org.apache.maven.repository.discovery.DefaultMetadataDiscoverer; +import org.apache.maven.repository.discovery.LegacyArtifactDiscoverer; +import org.apache.maven.repository.discovery.MetadataDiscoverer; +import org.apache.maven.repository.indexing.ArtifactRepositoryIndex; +import org.apache.maven.repository.indexing.MetadataRepositoryIndex; +import org.apache.maven.repository.indexing.PomRepositoryIndex; +import org.apache.maven.repository.indexing.RepositoryIndexException; +import org.apache.maven.repository.indexing.RepositoryIndexingFactory; +import org.codehaus.plexus.scheduler.AbstractJob; +import org.quartz.JobDataMap; +import org.quartz.JobExecutionContext; +import org.quartz.JobExecutionException; + +import java.io.File; +import java.net.MalformedURLException; +import java.util.Iterator; +import java.util.List; + +/** + * This class executes the discoverer and the indexer. + * + * @plexus.component role="org.apache.maven.repository.manager.web.job.DiscovererJob" + */ +public class DiscovererJob + extends AbstractJob +{ + public static final String ROLE = DiscovererJob.class.getName(); + + private ArtifactDiscoverer defaultArtifactDiscoverer; + + private ArtifactDiscoverer legacyArtifactDiscoverer; + + private MetadataDiscoverer defaultMetadataDiscoverer; + + private RepositoryIndexingFactory indexFactory; + + private ArtifactRepositoryLayout layout; + + private ArtifactRepositoryFactory repoFactory; + + public static String MAP_INDEXPATH = "INDEXPATH"; + + public static String MAP_LAYOUT = "LAYOUT"; + + public static String MAP_DEFAULT_REPOSITORY = "DEFAULT_REPOSITORY"; + + public static String MAP_BLACKLIST = "BLACKLISTED_PATTERNS"; + + public static String MAP_SNAPSHOTS = "INCLUDE_SNAPSHOTS"; + + public static String MAP_CONVERT = "CONVERT_SNAPSHOTS"; + + public static String MAP_DEF_ARTIFACT_DISCOVERER = "DEFAULT_ARTIFACT_DISCOVERER"; + + public static String MAP_LEG_ARTIFACT_DISCOVERER = "LEGACY_ARTIFACT_DISCOVERER"; + + public static String MAP_DEF_METADATA_DISCOVERER = "DEFAULT_METADATA_DISCOVERER"; + + public static String MAP_IDX_FACTORY = "INDEX_FACTORY"; + + public static String MAP_REPO_LAYOUT = "REPOSITORY_LAYOUT"; + + public static String MAP_REPO_FACTORY = "REPOSITORY_FACTORY"; + + /** + * Execute the discoverer and the indexer. + * + * @param context + * @throws org.quartz.JobExecutionException + * + */ + public void execute( JobExecutionContext context ) + throws JobExecutionException + { + System.out.println( "Start execution of DiscovererJob.." ); + JobDataMap dataMap = context.getJobDetail().getJobDataMap(); + + //configuration values specified in properties file + String indexPath = (String) dataMap.get( MAP_INDEXPATH ); + ArtifactRepository defaultRepository = (ArtifactRepository) dataMap.get( MAP_DEFAULT_REPOSITORY ); + String blacklistedPatterns = (String) dataMap.get( MAP_BLACKLIST ); + boolean includeSnapshots = ( (Boolean) dataMap.get( MAP_SNAPSHOTS ) ).booleanValue(); + boolean convertSnapshots = ( (Boolean) dataMap.get( MAP_CONVERT ) ).booleanValue(); + + //plexus components created in BaseAction + defaultArtifactDiscoverer = (DefaultArtifactDiscoverer) dataMap.get( MAP_DEF_ARTIFACT_DISCOVERER ); + legacyArtifactDiscoverer = (LegacyArtifactDiscoverer) dataMap.get( MAP_LEG_ARTIFACT_DISCOVERER ); + defaultMetadataDiscoverer = (DefaultMetadataDiscoverer) dataMap.get( MAP_DEF_METADATA_DISCOVERER ); + indexFactory = (RepositoryIndexingFactory) dataMap.get( MAP_IDX_FACTORY ); + layout = (ArtifactRepositoryLayout) dataMap.get( MAP_REPO_LAYOUT ); + repoFactory = (ArtifactRepositoryFactory) dataMap.get( MAP_REPO_FACTORY ); + + try + { + List artifacts; + if ( dataMap.get( MAP_LAYOUT ).equals( "default" ) ) + { + artifacts = defaultArtifactDiscoverer.discoverArtifacts( defaultRepository, blacklistedPatterns, + includeSnapshots ); + indexArtifact( artifacts, indexPath, defaultRepository ); + + List models = defaultArtifactDiscoverer.discoverStandalonePoms( defaultRepository, blacklistedPatterns, + convertSnapshots ); + indexPom( models, indexPath, defaultRepository ); + + List metadataList = defaultMetadataDiscoverer.discoverMetadata( + new File( defaultRepository.getBasedir() ), blacklistedPatterns ); + indexMetadata( metadataList, indexPath, new File( defaultRepository.getBasedir() ) ); + } + else if ( dataMap.get( MAP_LAYOUT ).equals( "legacy" ) ) + { + artifacts = legacyArtifactDiscoverer.discoverArtifacts( defaultRepository, blacklistedPatterns, + includeSnapshots ); + indexArtifact( artifacts, indexPath, defaultRepository ); + } + } + catch ( RepositoryIndexException e ) + { + e.printStackTrace(); + } + catch ( MalformedURLException me ) + { + me.printStackTrace(); + } + + System.out.println( "[DiscovererJob] DiscovererJob has finished executing." ); + } + + /** + * Index the artifacts in the list + * + * @param artifacts the artifacts to be indexed + * @param indexPath the path to the index file + * @param repository the repository where the artifacts are located + */ + private void indexArtifact( List artifacts, String indexPath, ArtifactRepository repository ) + throws RepositoryIndexException + { + ArtifactRepositoryIndex artifactIndex = indexFactory.createArtifactRepositoryIndex( indexPath, repository ); + for ( Iterator iter = artifacts.iterator(); iter.hasNext(); ) + { + Artifact artifact = (Artifact) iter.next(); + try + { + artifactIndex.indexArtifact( artifact ); + } + catch ( Exception e ) + { + if ( e instanceof RepositoryIndexException ) + { + throw (RepositoryIndexException) e; + } + } + + if ( artifactIndex.isOpen() ) + { + artifactIndex.optimize(); + artifactIndex.close(); + } + } + } + + /** + * Index the metadata in the list + * + * @param metadataList the metadata to be indexed + * @param indexPath the path to the index file + * @param repositoryBase the repository where the metadata are located + */ + private void indexMetadata( List metadataList, String indexPath, File repositoryBase ) + throws RepositoryIndexException, MalformedURLException + { + String repoDir = repositoryBase.toURL().toString(); + ArtifactRepository repository = + repoFactory.createArtifactRepository( "repository", repoDir, layout, null, null ); + + MetadataRepositoryIndex metadataIndex = indexFactory.createMetadataRepositoryIndex( indexPath, repository ); + for ( Iterator iter = metadataList.iterator(); iter.hasNext(); ) + { + RepositoryMetadata repoMetadata = (RepositoryMetadata) iter.next(); + try + { + metadataIndex.index( repoMetadata ); + } + catch ( Exception e ) + { + if ( e instanceof RepositoryIndexException ) + { + throw (RepositoryIndexException) e; + } + } + if ( metadataIndex.isOpen() ) + { + metadataIndex.optimize(); + metadataIndex.close(); + } + } + } + + /** + * Index the poms in the list + * + * @param models list of poms that will be indexed + * @param indexPath the path to the index + * @param repository the artifact repository where the poms were discovered + */ + private void indexPom( List models, String indexPath, ArtifactRepository repository ) + throws RepositoryIndexException + { + PomRepositoryIndex pomIndex = indexFactory.createPomRepositoryIndex( indexPath, repository ); + for ( Iterator iter = models.iterator(); iter.hasNext(); ) + { + Model model = (Model) iter.next(); + try + { + pomIndex.indexPom( model ); + } + catch ( Exception e ) + { + if ( e instanceof RepositoryIndexException ) + { + throw (RepositoryIndexException) e; + } + } + + if ( pomIndex.isOpen() ) + { + pomIndex.optimize(); + pomIndex.close(); + } + } + } + +} diff --git a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/job/DiscovererScheduler.java b/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/job/DiscovererScheduler.java new file mode 100644 index 000000000..202c86714 --- /dev/null +++ b/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/job/DiscovererScheduler.java @@ -0,0 +1,149 @@ +package org.apache.maven.repository.manager.web.job; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; +import org.apache.maven.artifact.repository.DefaultArtifactRepositoryFactory; +import org.apache.maven.repository.discovery.ArtifactDiscoverer; +import org.apache.maven.repository.discovery.MetadataDiscoverer; +import org.apache.maven.repository.indexing.RepositoryIndexingFactory; +import org.codehaus.plexus.scheduler.Scheduler; +import org.quartz.CronTrigger; +import org.quartz.JobDataMap; +import org.quartz.JobDetail; +import org.quartz.SchedulerException; + +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.text.ParseException; +import java.util.Properties; + +/** + * This class sets the job to be executed in the plexus-quartz scheduler + * + * @plexus.component role="org.apache.maven.repository.manager.web.job.DiscovererScheduler" + */ +public class DiscovererScheduler +{ + /** + * @plexus.requirement + */ + private Configuration config; + + /** + * @plexus.requirement + */ + private Scheduler scheduler; + + /** + * @plexus.requirement role="org.apache.maven.repository.discovery.ArtifactDiscoverer" role-hint="org.apache.maven.repository.discovery.DefaultArtifactDiscoverer" + */ + private ArtifactDiscoverer defaultArtifactDiscoverer; + + /** + * @plexus.requirement role="org.apache.maven.repository.discovery.ArtifactDiscoverer" role-hint="org.apache.maven.repository.discovery.LegacyArtifactDiscoverer" + */ + private ArtifactDiscoverer legacyArtifactDiscoverer; + + /** + * @plexus.requirement role="org.apache.maven.repository.discovery.MetadataDiscoverer" role-hint="org.apache.maven.repository.discovery.DefaultMetadataDiscoverer" + */ + private MetadataDiscoverer defaultMetadataDiscoverer; + + /** + * @plexus.requirement + */ + private RepositoryIndexingFactory indexFactory; + + /** + * @plexus.requirement + */ + private ArtifactRepositoryFactory repoFactory; + + private Properties props; + + /** + * Method that sets the schedule in the plexus-quartz scheduler + * + * @throws IOException + * @throws ParseException + * @throws SchedulerException + */ + public void setSchedule() + throws IOException, ParseException, SchedulerException + { + props = config.getProperties(); + JobDetail jobDetail = new JobDetail( "discovererJob", "DISCOVERER", DiscovererJob.class ); + JobDataMap dataMap = new JobDataMap(); + dataMap.put( DiscovererJob.MAP_INDEXPATH, props.getProperty( "index.path" ) ); + dataMap.put( DiscovererJob.MAP_BLACKLIST, props.getProperty( "blacklist.patterns" ) ); + dataMap.put( DiscovererJob.MAP_DEFAULT_REPOSITORY, getDefaultRepository() ); + dataMap.put( DiscovererJob.MAP_LAYOUT, props.getProperty( "layout" ) ); + dataMap.put( DiscovererJob.MAP_SNAPSHOTS, new Boolean( props.getProperty( "include.snapshots" ) ) ); + dataMap.put( DiscovererJob.MAP_CONVERT, new Boolean( props.getProperty( "convert.snapshots" ) ) ); + dataMap.put( DiscovererJob.MAP_DEF_ARTIFACT_DISCOVERER, defaultArtifactDiscoverer ); + dataMap.put( DiscovererJob.MAP_LEG_ARTIFACT_DISCOVERER, legacyArtifactDiscoverer ); + dataMap.put( DiscovererJob.MAP_DEF_METADATA_DISCOVERER, defaultMetadataDiscoverer ); + dataMap.put( DiscovererJob.MAP_IDX_FACTORY, indexFactory ); + dataMap.put( DiscovererJob.MAP_REPO_LAYOUT, config.getLayout() ); + dataMap.put( DiscovererJob.MAP_REPO_FACTORY, repoFactory ); + jobDetail.setJobDataMap( dataMap ); + + CronTrigger trigger = + new CronTrigger( "DiscovererTrigger", "DISCOVERER", props.getProperty( "cron.expression" ) ); + scheduler.scheduleJob( jobDetail, trigger ); + } + + /** + * Method that creates the artifact repository + * + * @return an ArtifactRepository instance + * @throws java.net.MalformedURLException + */ + private ArtifactRepository getDefaultRepository() + throws MalformedURLException + { + File repositoryDirectory = new File( config.getRepositoryDirectory() ); + String repoDir = repositoryDirectory.toURL().toString(); + ArtifactRepositoryFactory repoFactory = new DefaultArtifactRepositoryFactory(); + + return repoFactory.createArtifactRepository( "test", repoDir, config.getLayout(), null, null ); + } + + /** + * Method that sets the configuration object + * + * @param config + */ + public void setConfiguration( Configuration config ) + { + this.config = config; + } + + /** + * Returns the cofiguration + * + * @return a Configuration object that contains the configuration values + */ + public Configuration getConfiguration() + { + return config; + } + +} diff --git a/maven-repository-webapp/src/main/resources/xwork.xml b/maven-repository-webapp/src/main/resources/xwork.xml index 5c399c792..7e65ca10e 100644 --- a/maven-repository-webapp/src/main/resources/xwork.xml +++ b/maven-repository-webapp/src/main/resources/xwork.xml @@ -27,8 +27,9 @@ - + /WEB-INF/jsp/index.jsp + /WEB-INF/jsp/index.jsp diff --git a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/browse.jsp b/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/browse.jsp index af4523374..bf950fd65 100644 --- a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/browse.jsp +++ b/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/browse.jsp @@ -1,26 +1,28 @@ <%@ taglib uri="webwork" prefix="ww" %> -<%@page import="java.util.*"%> + -Repository Browser + Repository Browser +

">basedir / - - - - - - - - - - - - - "> / - - + + + + + + + + + + + + + "> / + +


@@ -29,54 +31,59 @@ -<% -int ctr = 1; -%> + <% + + int ctr = 1; + + %> - -<% -if (ctr == ((Integer)pageContext.getAttribute("in")).intValue()) {%> - - - /""> - / -
-
-<% -} -ctr++; -%> -
-
-
+ + <% - - - - - - - - - - - - - - - - - - - - - - - - - -
Group ID
Artifact ID
Version
Derivatives
Parent

+if (ctr == ((Integer)pageContext.getAttribute("in")).intValue()) { + %> + + +/""> + / +
+
+ <% + } + ctr++; + %> +
+
- + + + + + + + + + + + + + + + + + + + + + + + + + + +
Group ID
Artifact ID
Version
Derivatives
Parent
+
+
+
diff --git a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/form.jspf b/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/form.jspf index 4c9229e5c..93a134e5d 100644 --- a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/form.jspf +++ b/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/form.jspf @@ -34,30 +34,33 @@ + var _ns = (navigator.appName.indexOf("Netscape") >= 0 && ((_info.indexOf("Win") > 0 && _info.indexOf("Win16") < 0 && + java.lang.System.getProperty("os.version").indexOf("3.5") < + 0) || (_info.indexOf("Sun") > 0) || + (_info.indexOf("Linux") > 0) || + (_info.indexOf("AIX") > 0) || (_info.indexOf("OS/2") > 0) || + (_info.indexOf("IRIX") > 0))); + var _ns6 = ((_ns == true) && (_info.indexOf("Mozilla/5") >= 0)); + //--> diff --git a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/generalresults.jsp b/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/generalresults.jsp index 53217d373..bd9b1246b 100644 --- a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/generalresults.jsp +++ b/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/generalresults.jsp @@ -24,7 +24,7 @@

Maven Repository Manager

-<%@include file="form.jspf"%> +<%@ include file="form.jspf" %> @@ -50,8 +50,8 @@ diff --git a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/results.jsp b/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/results.jsp index f644419a4..bf9fb65e6 100644 --- a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/results.jsp +++ b/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/results.jsp @@ -24,7 +24,7 @@

Maven Repository Manager

-<%@include file="form.jspf"%> +<%@ include file="form.jspf" %>
- - + +
diff --git a/maven-repository-webapp/src/main/webapp/WEB-INF/plexus.xml b/maven-repository-webapp/src/main/webapp/WEB-INF/plexus.xml index 1e13278eb..d34d3cd0d 100644 --- a/maven-repository-webapp/src/main/webapp/WEB-INF/plexus.xml +++ b/maven-repository-webapp/src/main/webapp/WEB-INF/plexus.xml @@ -40,7 +40,7 @@ com.opensymphony.xwork.ObjectFactoryorg.codehaus.plexus.xwork.PlexusObjectFactory - + org.apache.maven.repository.manager.web.job.Configuration org.apache.maven.repository.manager.web.job.Configuration @@ -52,7 +52,7 @@ default.repository.dir - C:/TEST_REPOS/repository + C:/TEST_REPOS/.m2/repository/ legacy.repository.dir @@ -82,14 +82,6 @@ - - -