aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-database/src
diff options
context:
space:
mode:
authorJoakim Erdfelt <joakime@apache.org>2007-06-17 04:50:05 +0000
committerJoakim Erdfelt <joakime@apache.org>2007-06-17 04:50:05 +0000
commite7664898d68e9230f12a111cc3e18bbc6a3374bf (patch)
tree8acaedf5aa03cca0c55b0f17e5c9d5cf5053d334 /archiva-database/src
parent743213aaf3e9d087eff72a53dd7082bd437c888c (diff)
downloadarchiva-e7664898d68e9230f12a111cc3e18bbc6a3374bf.tar.gz
archiva-e7664898d68e9230f12a111cc3e18bbc6a3374bf.zip
[MRM-410] Dependency Tree is not shown in artifact details screen.
* Refactored project resolution into ProjectModelResolverFactory component. * All resolution access points now use this factory. * Created ResolverFactoryInit as plexus component load-on-start, to hookup database to resolver stack. * Created archiva:dependency-tree taglib git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@548008 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-database/src')
-rw-r--r--archiva-database/src/main/java/org/apache/maven/archiva/database/project/DatabaseProjectModelResolver.java66
-rw-r--r--archiva-database/src/main/java/org/apache/maven/archiva/database/project/ProjectModelToDatabaseListener.java153
2 files changed, 219 insertions, 0 deletions
diff --git a/archiva-database/src/main/java/org/apache/maven/archiva/database/project/DatabaseProjectModelResolver.java b/archiva-database/src/main/java/org/apache/maven/archiva/database/project/DatabaseProjectModelResolver.java
new file mode 100644
index 000000000..8c1f7ec4d
--- /dev/null
+++ b/archiva-database/src/main/java/org/apache/maven/archiva/database/project/DatabaseProjectModelResolver.java
@@ -0,0 +1,66 @@
+package org.apache.maven.archiva.database.project;
+
+/*
+ * 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.maven.archiva.database.ArchivaDAO;
+import org.apache.maven.archiva.database.ArchivaDatabaseException;
+import org.apache.maven.archiva.database.ObjectNotFoundException;
+import org.apache.maven.archiva.model.ArchivaProjectModel;
+import org.apache.maven.archiva.model.VersionedReference;
+import org.apache.maven.archiva.repository.project.ProjectModelException;
+import org.apache.maven.archiva.repository.project.ProjectModelResolver;
+
+/**
+ * Resolves a project model from the database.
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ *
+ * @plexus.component role="org.apache.maven.archiva.repository.project.ProjectModelResolver"
+ * role-hint="database"
+ */
+public class DatabaseProjectModelResolver
+ implements ProjectModelResolver
+{
+ /**
+ * @plexus.requirement role-hint="jdo"
+ */
+ private ArchivaDAO dao;
+
+ public ArchivaProjectModel resolveProjectModel( VersionedReference reference )
+ throws ProjectModelException
+ {
+ try
+ {
+ ArchivaProjectModel model = dao.getProjectModelDAO().getProjectModel( reference.getGroupId(),
+ reference.getArtifactId(),
+ reference.getVersion() );
+ return model;
+ }
+ catch ( ObjectNotFoundException e )
+ {
+ return null;
+ }
+ catch ( ArchivaDatabaseException e )
+ {
+ return null;
+ }
+ }
+}
diff --git a/archiva-database/src/main/java/org/apache/maven/archiva/database/project/ProjectModelToDatabaseListener.java b/archiva-database/src/main/java/org/apache/maven/archiva/database/project/ProjectModelToDatabaseListener.java
new file mode 100644
index 000000000..b4afc78d4
--- /dev/null
+++ b/archiva-database/src/main/java/org/apache/maven/archiva/database/project/ProjectModelToDatabaseListener.java
@@ -0,0 +1,153 @@
+package org.apache.maven.archiva.database.project;
+
+/*
+ * 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.maven.archiva.database.ArchivaDAO;
+import org.apache.maven.archiva.database.ArchivaDatabaseException;
+import org.apache.maven.archiva.database.ObjectNotFoundException;
+import org.apache.maven.archiva.model.ArchivaProjectModel;
+import org.apache.maven.archiva.model.VersionedReference;
+import org.apache.maven.archiva.repository.project.ProjectModelException;
+import org.apache.maven.archiva.repository.project.ProjectModelResolver;
+import org.apache.maven.archiva.repository.project.resolvers.FilesystemBasedResolver;
+import org.apache.maven.archiva.repository.project.resolvers.ProjectModelResolutionListener;
+import org.codehaus.plexus.logging.AbstractLogEnabled;
+
+import java.util.List;
+
+/**
+ * Just in Time save of project models to the database, implemented as a listener
+ * on {@link ProjectModelResolver} objects that implement {@link FilesystemBasedResolver}.
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ *
+ * @plexus.component
+ * role="org.apache.maven.archiva.repository.project.resolvers.ProjectModelResolutionListener"
+ * role-hint="model-to-db"
+ */
+public class ProjectModelToDatabaseListener
+ extends AbstractLogEnabled
+ implements ProjectModelResolutionListener
+{
+ /**
+ * @plexus.requirement role-hint="jdo"
+ */
+ private ArchivaDAO dao;
+
+ private void saveInDatabase( ArchivaProjectModel model )
+ throws ProjectModelException
+ {
+ try
+ {
+ dao.getProjectModelDAO().saveProjectModel( model );
+ }
+ catch ( ArchivaDatabaseException e )
+ {
+ throw new ProjectModelException( "Unable to save model to database: " + e.getMessage(), e );
+ }
+ }
+
+ private void removeFromDatabase( ArchivaProjectModel model )
+ throws ProjectModelException
+ {
+ try
+ {
+ dao.getProjectModelDAO().deleteProjectModel( model );
+ }
+ catch ( ArchivaDatabaseException e )
+ {
+ throw new ProjectModelException( "Unable to remove existing model from database: " + e.getMessage(), e );
+ }
+ }
+
+ private boolean existsInDatabase( ArchivaProjectModel model )
+ throws ProjectModelException
+ {
+ try
+ {
+ ArchivaProjectModel dbmodel = dao.getProjectModelDAO().getProjectModel( model.getGroupId(),
+ model.getArtifactId(),
+ model.getVersion() );
+
+ return ( dbmodel != null );
+ }
+ catch ( ObjectNotFoundException e )
+ {
+ return false;
+ }
+ catch ( ArchivaDatabaseException e )
+ {
+ throw new ProjectModelException( "Unable to check for existing model from database: " + e.getMessage(), e );
+ }
+ }
+
+ public void resolutionAttempting( VersionedReference projectRef, ProjectModelResolver resolver )
+ {
+ /* do nothing */
+ }
+
+ public void resolutionError( VersionedReference projectRef, ProjectModelResolver resolver, Exception cause )
+ {
+ /* do nothing */
+ }
+
+ public void resolutionMiss( VersionedReference projectRef, ProjectModelResolver resolver )
+ {
+ /* do nothing */
+ }
+
+ public void resolutionNotFound( VersionedReference projectRef, List resolverList )
+ {
+ /* do nothing */
+ }
+
+ public void resolutionStart( VersionedReference projectRef, List resolverList )
+ {
+ /* do nothing */
+ }
+
+ public void resolutionSuccess( VersionedReference projectRef, ProjectModelResolver resolver,
+ ArchivaProjectModel model )
+ {
+ if ( !( resolver instanceof FilesystemBasedResolver ) )
+ {
+ // Nothing to do. skip it.
+ return;
+ }
+
+ model.setOrigin( "filesystem" );
+
+ try
+ {
+ // Test if it exists.
+ if ( existsInDatabase( model ) )
+ {
+ removeFromDatabase( model );
+ }
+
+ saveInDatabase( model );
+ }
+ catch ( ProjectModelException e )
+ {
+ getLogger().warn( e.getMessage(), e );
+ }
+ }
+}