You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by br...@apache.org on 2006/12/04 01:07:28 UTC
svn commit: r481993 - in
/maven/shared/trunk/maven-app-configuration/web/src/main/java/org/apache/maven/shared/app/company:
CompanyPomHandler.java DefaultCompanyPomHandler.java
Author: brett
Date: Sun Dec 3 16:07:26 2006
New Revision: 481993
URL: http://svn.apache.org/viewvc?view=rev&rev=481993
Log:
make it possible to deal with remote repositories
Modified:
maven/shared/trunk/maven-app-configuration/web/src/main/java/org/apache/maven/shared/app/company/CompanyPomHandler.java
maven/shared/trunk/maven-app-configuration/web/src/main/java/org/apache/maven/shared/app/company/DefaultCompanyPomHandler.java
Modified: maven/shared/trunk/maven-app-configuration/web/src/main/java/org/apache/maven/shared/app/company/CompanyPomHandler.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-app-configuration/web/src/main/java/org/apache/maven/shared/app/company/CompanyPomHandler.java?view=diff&rev=481993&r1=481992&r2=481993
==============================================================================
--- maven/shared/trunk/maven-app-configuration/web/src/main/java/org/apache/maven/shared/app/company/CompanyPomHandler.java (original)
+++ maven/shared/trunk/maven-app-configuration/web/src/main/java/org/apache/maven/shared/app/company/CompanyPomHandler.java Sun Dec 3 16:07:26 2006
@@ -19,6 +19,7 @@
* under the License.
*/
+import org.apache.maven.artifact.deployer.ArtifactDeploymentException;
import org.apache.maven.artifact.installer.ArtifactInstallationException;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.repository.ArtifactRepository;
@@ -27,6 +28,7 @@
import org.apache.maven.shared.app.configuration.CompanyPom;
import java.io.IOException;
+import java.util.List;
/**
* Holds a company POM to avoid re-reading it.
@@ -40,8 +42,8 @@
/**
* Retrieve the company model (may be cached).
*
- * @param companyPom the configuration holding the required group and artifact ID
- * @param localRepository
+ * @param companyPom the configuration holding the required group and artifact ID
+ * @param localRepository the local repository to use while resolving the POM
* @return the model
* @throws org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException
* if there is a problem locating the existing POM from the repository
@@ -52,15 +54,47 @@
throws ProjectBuildingException, ArtifactMetadataRetrievalException;
/**
+ * Retrieve the company model (may be cached).
+ *
+ * @param companyPom the configuration holding the required group and artifact ID
+ * @param localRepository the local repository to use while resolving the POM
+ * @param remoteRepositories the repositories to search for the POM. The default repositories from the super POM will also be used if necessary.
+ * @return the model
+ * @throws org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException
+ * if there is a problem locating the existing POM from the repository
+ * @throws org.apache.maven.project.ProjectBuildingException
+ * if the existing POM in the repository is invalid
+ */
+ Model getCompanyPomModel( CompanyPom companyPom, ArtifactRepository localRepository,
+ List/*<ArtifactRepository>*/ remoteRepositories )
+ throws ProjectBuildingException, ArtifactMetadataRetrievalException;
+
+ /**
* Save a company POM in the repository. At present, it does not deploy it to any remote repositories.
* The version in the model will be incremented to the next sequential single digit.
*
- * @param companyModel the company model to save. This is likely to be the same instance already cached, but will replace the cached version regardless
- * @param localRepository
+ * @param companyModel the company model to save. This is likely to be the same instance already cached, but will replace the cached version regardless
+ * @param localRepository the local repository to use while deploying the POM.
* @throws java.io.IOException if there is a problem saving the model to the local repository
* @throws org.apache.maven.artifact.installer.ArtifactInstallationException
* if there is a problem saving to the local repository
*/
void save( Model companyModel, ArtifactRepository localRepository )
throws IOException, ArtifactInstallationException;
+
+ /**
+ * Save a company POM in the repository. At present, it does not deploy it to any remote repositories.
+ * The version in the model will be incremented to the next sequential single digit.
+ *
+ * @param companyModel the company model to save. This is likely to be the same instance already cached, but will replace the cached version regardless
+ * @param localRepository the local repository to use while deploying the POM.
+ * @param deploymentRepository the repository to deploy the final POM to. If <code>null</code>, the POM is not deployed.
+ * @throws java.io.IOException if there is a problem saving the model to the local repository
+ * @throws org.apache.maven.artifact.installer.ArtifactInstallationException
+ * if there is a problem saving to the local repository
+ * @throws org.apache.maven.artifact.deployer.ArtifactDeploymentException
+ * if there is a problem deploying to the remote repository
+ */
+ void save( Model companyModel, ArtifactRepository localRepository, ArtifactRepository deploymentRepository )
+ throws IOException, ArtifactInstallationException, ArtifactDeploymentException;
}
Modified: maven/shared/trunk/maven-app-configuration/web/src/main/java/org/apache/maven/shared/app/company/DefaultCompanyPomHandler.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-app-configuration/web/src/main/java/org/apache/maven/shared/app/company/DefaultCompanyPomHandler.java?view=diff&rev=481993&r1=481992&r2=481993
==============================================================================
--- maven/shared/trunk/maven-app-configuration/web/src/main/java/org/apache/maven/shared/app/company/DefaultCompanyPomHandler.java (original)
+++ maven/shared/trunk/maven-app-configuration/web/src/main/java/org/apache/maven/shared/app/company/DefaultCompanyPomHandler.java Sun Dec 3 16:07:26 2006
@@ -19,28 +19,31 @@
* under the License.
*/
-import org.apache.maven.model.Model;
-import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.deployer.ArtifactDeployer;
+import org.apache.maven.artifact.deployer.ArtifactDeploymentException;
import org.apache.maven.artifact.factory.ArtifactFactory;
-import org.apache.maven.artifact.installer.ArtifactInstaller;
import org.apache.maven.artifact.installer.ArtifactInstallationException;
-import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
+import org.apache.maven.artifact.installer.ArtifactInstaller;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
+import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
+import org.apache.maven.model.Model;
+import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
+import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.ProjectBuildingException;
-import org.apache.maven.project.MavenProject;
import org.apache.maven.shared.app.configuration.CompanyPom;
-import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.StringUtils;
-import java.util.Collections;
-import java.util.List;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
/**
* Holds a company POM from the repository, and is able to find the latest one in a repository.
@@ -77,10 +80,22 @@
private static final String ORGANIZATION_LOGO_PROPERTY = "organization.logo";
+ /**
+ * @plexus.requirement
+ */
+ private ArtifactDeployer deployer;
+
public Model getCompanyPomModel( CompanyPom companyPom, ArtifactRepository localRepository )
throws ProjectBuildingException, ArtifactMetadataRetrievalException
{
+ return getCompanyPomModel( companyPom, localRepository, Collections.EMPTY_LIST );
+ }
+
+ public Model getCompanyPomModel( CompanyPom companyPom, ArtifactRepository localRepository,
+ List remoteRepositories )
+ throws ProjectBuildingException, ArtifactMetadataRetrievalException
+ {
if ( companyPom != null )
{
if ( StringUtils.isNotEmpty( companyPom.getGroupId() ) &&
@@ -101,8 +116,9 @@
companyPom.getArtifactId(),
Artifact.RELEASE_VERSION );
- List repositories =
- projectBuilder.buildStandaloneSuperProject( localRepository ).getRemoteArtifactRepositories();
+ List repositories = new ArrayList( remoteRepositories );
+ repositories.addAll(
+ projectBuilder.buildStandaloneSuperProject( localRepository ).getRemoteArtifactRepositories() );
List versions =
artifactMetadataSource.retrieveAvailableVersions( artifact, localRepository, repositories );
@@ -153,6 +169,17 @@
public void save( Model companyModel, ArtifactRepository localRepository )
throws IOException, ArtifactInstallationException
{
+ Artifact artifact = getNewArtifact( companyModel );
+
+ File f = writeTempFile( companyModel );
+
+ installer.install( f, artifact, localRepository );
+
+ this.companyModel = companyModel;
+ }
+
+ private Artifact getNewArtifact( Model companyModel )
+ {
String v = companyModel.getVersion();
String newVersion;
if ( v != null )
@@ -167,9 +194,13 @@
}
companyModel.setVersion( newVersion );
- Artifact artifact = artifactFactory.createProjectArtifact( companyModel.getGroupId(),
- companyModel.getArtifactId(), newVersion );
+ return artifactFactory.createProjectArtifact( companyModel.getGroupId(), companyModel.getArtifactId(),
+ newVersion );
+ }
+ private static File writeTempFile( Model companyModel )
+ throws IOException
+ {
File f = File.createTempFile( "maven", "pom" );
f.deleteOnExit();
@@ -183,9 +214,23 @@
{
IOUtil.close( fileWriter );
}
+ return f;
+ }
+
+ public void save( Model companyModel, ArtifactRepository localRepository, ArtifactRepository deploymentRepository )
+ throws IOException, ArtifactInstallationException, ArtifactDeploymentException
+ {
+ Artifact artifact = getNewArtifact( companyModel );
+
+ File f = writeTempFile( companyModel );
installer.install( f, artifact, localRepository );
this.companyModel = companyModel;
+
+ if ( deploymentRepository != null )
+ {
+ deployer.deploy( f, artifact, deploymentRepository, localRepository );
+ }
}
}