Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

Commit

Permalink
BZ1121179: Add Support for Distribution Management in Parent POMs
Browse files Browse the repository at this point in the history
(cherry picked from commit f583730)
  • Loading branch information
manstis committed Jan 7, 2015
1 parent 6094251 commit 3851cca
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
5 changes: 4 additions & 1 deletion guvnor-m2repo-editor/guvnor-m2repo-editor-backend/pom.xml
Expand Up @@ -65,7 +65,10 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>

<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
</dependency>

<dependency>
<groupId>org.guvnor</groupId>
Expand Down
Expand Up @@ -16,6 +16,7 @@

package org.guvnor.m2repo.backend.server;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
Expand All @@ -26,6 +27,7 @@
import java.io.StringReader;
import java.io.StringWriter;
import java.net.MalformedURLException;
import java.nio.charset.Charset;
import java.util.Collection;
import java.util.Enumeration;
import java.util.Properties;
Expand All @@ -45,12 +47,11 @@
import org.apache.maven.model.DeploymentRepository;
import org.apache.maven.model.DistributionManagement;
import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
import org.apache.maven.project.MavenProject;
import org.apache.maven.settings.Server;
import org.apache.maven.settings.Settings;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import org.drools.core.io.impl.ReaderInputStream;
import org.eclipse.aether.artifact.Artifact;
import org.eclipse.aether.artifact.DefaultArtifact;
Expand All @@ -64,6 +65,7 @@
import org.eclipse.aether.util.repository.AuthenticationBuilder;
import org.guvnor.common.services.project.model.GAV;
import org.kie.scanner.Aether;
import org.kie.scanner.embedder.MavenProjectLoader;
import org.kie.scanner.embedder.MavenSettings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -327,8 +329,7 @@ private void deployArtifact( final GAV gav,

//Deploy into remote repository defined in <distributionManagement>
try {
final Model model = new MavenXpp3Reader().read( new StringReader( pomXML ) );
final DistributionManagement distributionManagement = model.getDistributionManagement();
DistributionManagement distributionManagement = getDistributionManagement( pomXML );

if ( distributionManagement != null ) {

Expand Down Expand Up @@ -362,10 +363,6 @@ private void deployArtifact( final GAV gav,

} catch ( DeploymentException e ) {
throw new RuntimeException( e );
} catch ( XmlPullParserException xppe ) {
throw new RuntimeException( xppe );
} catch ( IOException ioe ) {
throw new RuntimeException( ioe );
}

} finally {
Expand All @@ -377,6 +374,25 @@ private void deployArtifact( final GAV gav,
}
}

private DistributionManagement getDistributionManagement( final String pomXML ) {
final InputStream is = new ByteArrayInputStream( pomXML.getBytes( Charset.forName( "UTF-8" ) ) );
try {
//Get the effective POM as the DistributionManagement section may be in a parent POM
final MavenProject project = MavenProjectLoader.parseMavenPom( is );
final DistributionManagement distributionManagement = project.getDistributionManagement();

return distributionManagement;

} finally {
try {
is.close();
} catch ( IOException ioe ) {
//Swallow
}
}

}

private RemoteRepository getGuvnorM2Repository() {
File m2RepoDir = new File( M2_REPO_DIR );
if ( !m2RepoDir.exists() ) {
Expand Down

0 comments on commit 3851cca

Please sign in to comment.