Skip to content

Commit

Permalink
Merge pull request #6 from ebarboni/clusterrewrite
Browse files Browse the repository at this point in the history
cluster generation must use maven coordinate if available
  • Loading branch information
ebarboni authored Jun 8, 2020
2 parents 2b61d7a + 52a5b0d commit 917eab1
Showing 1 changed file with 62 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
* A goal for identifying NetBeans modules from the installation and populating the local
* repository with them. Optionally you can also deploy to a remote repository.
* <p>
* If you are looking for an existing remote repository for NetBeans artifacts, check out <a href="https://search.maven.org/">Maven Central</a>.
* If you are looking for an existing remote repository for NetBeans artifacts, check out <a href="https://search.maven.org/">Maven Central</a>.
* <a href="http://bits.netbeans.org/nexus/content/groups/netbeans/">http://bits.netbeans.org/nexus/content/groups/netbeans/</a>,
* contains contains API artifacts for older NetBeans releases.
* <a href="https://repository.apache.org/content/groups/snapshots">https://repository.apache.org/content/groups/snapshots</a>
Expand All @@ -105,15 +105,15 @@ public class PopulateRepositoryMojo
private static final String GROUP_EXTERNAL = ".external";
private static final String GROUP_CLUSTER = ".cluster";


/**
* a prefix for groupId of generated content,
* a prefix for groupId of generated content,
* eg. for org.netbeans value will generate org.netbeans.cluster groupId for clusters and org.netbeans.modules for module artifacts.
* @since 1.2
*/
@Parameter( property = "groupIdPrefix", defaultValue = "org.netbeans" )
private String groupIdPrefix;

/**
* an url where to deploy the NetBeans artifacts. Optional, if not specified, the artifacts will be only installed
* in local repository, if you need to give credentials to access remote repo, the id of the server is hardwired to "netbeans".
Expand All @@ -126,7 +126,7 @@ public class PopulateRepositoryMojo
*/
@Parameter( defaultValue = "netbeans" , property = "deployId" )
private String deployId;

/**
* By default the generated metadata is installed in local repository.
* Setting this parameter to false will avoid installing the bits. Only meaningful together with
Expand Down Expand Up @@ -195,7 +195,7 @@ public class PopulateRepositoryMojo
* Only meaningful when {@code forcedVersion} is defined.
* @since 3.7
*/
@Parameter( defaultValue = "true", property = "defineCluster" )
@Parameter( defaultValue = "true", property = "defineCluster" )
private boolean defineCluster;

/**
Expand Down Expand Up @@ -224,7 +224,7 @@ public class PopulateRepositoryMojo
*/
@Parameter( property = "parentGAV", required = false )
private String parentGAV;

// <editor-fold defaultstate="collapsed" desc="Component parameters">
/**
* Local maven repository.
Expand Down Expand Up @@ -283,12 +283,12 @@ public void execute()
Project antProject = antProject();
ArtifactRepository deploymentRepository = null;

if ( parentGAV != null )
if ( parentGAV != null )
{
// populate artefactParent
artefactParent = new Parent();
String[] split = parentGAV.split( ":" );
if ( split.length != 3 )
if ( split.length != 3 )
{
throw new MojoExecutionException(
"parentGAV should respect the following format groupId:artefactId:version" );
Expand Down Expand Up @@ -385,7 +385,7 @@ else if ( skipLocalInstall )
if ( "core-base".equals( artifact ) )
{
artifact = "org-netbeans-core-startup-base";
}
}
String version = forcedVersion == null ? examinator.getSpecVersion() : forcedVersion;
String group = groupIdPrefix + ( examinator.isOsgiBundle() ? GROUP_EXTERNAL : examinator.hasPublicPackages() ? GROUP_API : GROUP_IMPL );
Artifact art = createArtifact( artifact, version, group );
Expand All @@ -395,7 +395,7 @@ else if ( skipLocalInstall )
Dependency dep = findExternal( module );
if ( dep != null )
{

art = createArtifact( dep.getArtifactId(), dep.getVersion(), dep.getGroupId() );
group = dep.getGroupId();
version = dep.getVersion();
Expand All @@ -413,7 +413,7 @@ else if ( skipLocalInstall )
col.add( wr );
}
}

File javadocRoot = null;
if ( netbeansJavadocDirectory != null )
{
Expand Down Expand Up @@ -453,10 +453,10 @@ else if ( skipLocalInstall )
Map<ModuleWrapper, Artifact> tobePopulated = new HashMap<>();
// external artefacts
Map<ModuleWrapper, Artifact> oncentralWrapper = new HashMap<>();
// triage
for ( Map.Entry<ModuleWrapper, Artifact> entry : moduleDefinitions.entrySet() )
// triage
for ( Map.Entry<ModuleWrapper, Artifact> entry : moduleDefinitions.entrySet() )
{
if ( entry.getKey() instanceof ModuleWrapperMaven )
if ( entry.getKey() instanceof ModuleWrapperMaven )
{
oncentralWrapper.put( entry.getKey(), entry.getValue() );
}
Expand All @@ -468,8 +468,8 @@ else if ( skipLocalInstall )
List<ExternalsWrapper> externals = new ArrayList<>();
int count = tobePopulated.size() + 1;
int index = 0;


try
{
for ( Map.Entry<ModuleWrapper, Artifact> elem : tobePopulated.entrySet() )
Expand Down Expand Up @@ -553,7 +553,7 @@ else if ( skipLocalInstall )
b.append( ' ' );
}
b.append( dep.getGroupId() ).append( ':' ).append( dep.getArtifactId() ).append( ':' ).append( dep.getVersion() );
if ( dep.getClassifier() != null )
if ( dep.getClassifier() != null )
{
b.append( ":" ).append( dep.getClassifier() );
}
Expand Down Expand Up @@ -786,7 +786,7 @@ private File createMavenProject( ModuleWrapper wrapper, List<ModuleWrapper> wrap
mavenModel.setVersion( wrapper.getVersion() );
mavenModel.setPackaging( "jar" );
mavenModel.setModelVersion( "4.0.0" );
if ( artefactParent != null )
if ( artefactParent != null )
{
mavenModel.setParent( artefactParent );
}
Expand All @@ -806,8 +806,8 @@ private File createMavenProject( ModuleWrapper wrapper, List<ModuleWrapper> wrap
if ( wr instanceof ModuleWrapperMaven )
{
dep = ( ( ModuleWrapperMaven ) wr ).getDep();
}
else
}
else
{
dep = new Dependency();
dep.setArtifactId( wr.getArtifact() );
Expand All @@ -817,7 +817,7 @@ private File createMavenProject( ModuleWrapper wrapper, List<ModuleWrapper> wrap
dep.setType( "jar" );
//we don't want the API modules to depend on non-api ones..
// otherwise the transitive dependency mechanism pollutes your classpath..
if ( wrapper.getModuleManifest().hasPublicPackages()
if ( wrapper.getModuleManifest().hasPublicPackages()
&& !wr.getModuleManifest().hasPublicPackages() )
{
dep.setScope( "runtime" );
Expand All @@ -837,13 +837,13 @@ else if ( dependencyRepositoryUrl != null )
dep.setVersion( forcedVersion );
ArtifactRepositoryPolicy policy = new ArtifactRepositoryPolicy();
List<ArtifactRepository> repos = Collections.singletonList(
repositoryFactory.createArtifactRepository(
repositoryFactory.createArtifactRepository(
dependencyRepositoryId, dependencyRepositoryUrl, artifactRepositoryLayout, policy, policy ) );
try
{
artifactResolver.resolve(
artifactFactory.createBuildArtifact( groupIdPrefix + GROUP_API, artifactId, forcedVersion, "pom" ),
repos,
repos,
localRepository );
dep.setGroupId( groupIdPrefix + GROUP_API );
}
Expand Down Expand Up @@ -875,7 +875,7 @@ else if ( dependencyRepositoryUrl != null )
throw new MojoExecutionException( "No module found for dependency '" + elem + "'", x );
}


}

}
Expand Down Expand Up @@ -973,22 +973,22 @@ private Dependency findExternal( File f )
{
List<String> content512 = Files.readAllLines( externallist.toPath() );
MessageDigest shaDig = MessageDigest.getInstance( "SHA1" );

try ( InputStream is = new FileInputStream( f ); OutputStream os = new DigestOutputStream( new NullOutputStream(), shaDig ); )
{
IOUtil.copy( is, os );
}
String sha1 = encode ( shaDig.digest() ).toUpperCase();
for ( String string : content512 )
for ( String string : content512 )
{
if ( string.startsWith( "#" ) )
if ( string.startsWith( "#" ) )
{
continue;
}
String[] split = string.split( ";" );
if ( split[0].equals( sha1 ) && split[1].contains( ":" ) )
if ( split[0].equals( sha1 ) && split[1].contains( ":" ) )
{
Dependency dep = splitDependencyString( split[1] );
Dependency dep = splitDependencyString( split[1] );
getLog().info( "found match " + dep.getGroupId() + ":" + dep.getArtifactId() + ":" + dep.getVersion() + " for " + f.getName() );
return dep;
}
Expand All @@ -1002,7 +1002,7 @@ private Dependency findExternal( File f )
return null;
}

static Dependency splitDependencyString( String split )
static Dependency splitDependencyString( String split )
{
String[] splits = split.split( ":" );
Dependency dep = new Dependency();
Expand All @@ -1022,11 +1022,11 @@ static Dependency splitDependencyString( String split )
else
{
dep.setClassifier( splits[3] );
}
}
}
return dep;
}

File createExternalProject( ExternalsWrapper wrapper )
{
Model mavenModel = new Model();
Expand All @@ -1036,13 +1036,13 @@ File createExternalProject( ExternalsWrapper wrapper )
mavenModel.setVersion( wrapper.getVersion() );
mavenModel.setPackaging( "jar" );
mavenModel.setModelVersion( "4.0.0" );
if ( artefactParent != null )
if ( artefactParent != null )
{
mavenModel.setParent( artefactParent );
}
mavenModel.setName(
mavenModel.setName(
"Maven definition for " + wrapper.getFile().getName() + " - external part of NetBeans module." );
mavenModel.setDescription(
mavenModel.setDescription(
"POM and identification for artifact that was not possible to uniquely identify as a maven dependency." );
FileWriter writer = null;
File fil = null;
Expand Down Expand Up @@ -1086,26 +1086,41 @@ private File createClusterProject( Artifact cluster, Collection<ModuleWrapper> m
// mavenModel.setPackaging("nbm-application");
mavenModel.setPackaging( "pom" );
mavenModel.setModelVersion( "4.0.0" );
if ( artefactParent != null )
if ( artefactParent != null )
{
mavenModel.setParent( artefactParent );
}
List<Dependency> deps = new ArrayList<>();
for ( ModuleWrapper wr : mods )
{
Dependency dep = new Dependency();
dep.setArtifactId( wr.getArtifact() );
dep.setGroupId( wr.getGroup() );
dep.setVersion( wr.getVersion() );
if ( wr.getModuleManifest().isNetBeansModule() )
{
dep.setArtifactId( wr.getArtifact() );
dep.setGroupId( wr.getGroup() );
dep.setVersion( wr.getVersion() );
dep.setType( "nbm-file" );
}
else if ( wr instanceof ModuleWrapperMaven )
{
ModuleWrapperMaven mwr = ( ModuleWrapperMaven ) wr;
dep.setArtifactId( mwr.getDep().getArtifactId() );
dep.setGroupId( mwr.getDep().getGroupId() );
dep.setVersion( mwr.getDep().getVersion() );
dep.setClassifier( mwr.getDep().getClassifier() );
dep.setScope( mwr.getDep().getScope());
}
else
{
dep.setArtifactId( wr.getArtifact() );
dep.setGroupId( wr.getGroup() );
dep.setVersion( wr.getVersion() );
}
deps.add( dep );
}
mavenModel.setDependencies( deps );
//
//
//
//
// Build build = new Build();
// Plugin plg = new Plugin();
// plg.setGroupId("org.codehaus.mojo");
Expand Down Expand Up @@ -1145,7 +1160,7 @@ private Artifact createClusterArtifact( String artifact, String version )
{
return artifactFactory.createBuildArtifact( groupIdPrefix + GROUP_CLUSTER, artifact, version, "pom" );
}

private static final Pattern PATTERN_CLUSTER = Pattern.compile( "([a-zA-Z]+)[0-9\\.]*" );
static String stripClusterName( String key )
{
Expand Down Expand Up @@ -1209,11 +1224,11 @@ public void setVersion( String version )

}

private static class ModuleWrapperMaven extends ModuleWrapper
private static class ModuleWrapperMaven extends ModuleWrapper
{

private final Dependency dep;

ModuleWrapperMaven( String art, String ver, String grp, ExamineManifest manifest, File fil, Dependency de )
{
super( art, ver, grp, manifest, fil );
Expand All @@ -1223,9 +1238,9 @@ private static class ModuleWrapperMaven extends ModuleWrapper
public Dependency getDep()
{
return dep;
}
}
}

private static class ModuleWrapper
{

Expand Down

0 comments on commit 917eab1

Please sign in to comment.