org.apache.maven.archetype.catalog.Archetype Java Examples

The following examples show how to use org.apache.maven.archetype.catalog.Archetype. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Fabric8ArchetypeCatalogStep.java    From fabric8-forge with Apache License 2.0 6 votes vote down vote up
@Override
protected void setArchetypeArtifactId(String archetypeArtifactId) {
    super.setArchetypeArtifactId(archetypeArtifactId);
    if (Strings.isNotBlank(archetypeArtifactId)) {
        if (Strings.isNullOrBlank(getArchetypeVersion())) {
            String version = null;
            if (catalogFactory != null) {
                List<Archetype> archetypes = catalogFactory.getArchetypeCatalog().getArchetypes();
                for (Archetype archetype : archetypes) {
                    if (Objects.equal(archetype.getArtifactId(), archetypeArtifactId)) {
                        version = archetype.getVersion();
                    }
                }
            }
            if (Strings.isNullOrBlank(version)) {
                version = VersionHelper.fabric8ArchetypesVersion();
            }
            if (version != null) {
                setArchetypeVersion(version);
            } else {
                throw new IllegalArgumentException("Could not find an archetype for id " + archetypeArtifactId
                        + " in the archetype catalog " + catalogFactory + " or find version for environment variable " + VersionHelper.ENV_FABRIC8_ARCHETYPES_VERSION);
            }
        }
    }
}
 
Example #2
Source File: DataflowProjectCreatorTest.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
@Test
public void testRun_propagatesCoreException()
    throws OperationCanceledException, InterruptedException, CoreException {
  IProjectConfigurationManager manager = mock(IProjectConfigurationManager.class);
  CoreException exception = new CoreException(StatusUtil.error(this, "test error message"));
  doThrow(exception).when(manager).createArchetypeProjects(
      any(IPath.class), any(Archetype.class), anyString(), anyString(), anyString(), anyString(),
      any(Properties.class), any(ProjectImportConfiguration.class), any(IProgressMonitor.class));

  DataflowProjectCreator creator = new DataflowProjectCreator(manager);
  creator.setMavenGroupId("com.example");
  creator.setMavenArtifactId("some-artifact-id");
  creator.setPackage("com.example");
  creator.setArchetypeVersion("123.456.789");
  try {
    creator.run(new NullProgressMonitor());
    fail();
  } catch (InvocationTargetException ex) {
    assertEquals(exception, ex.getCause());
  }
}
 
Example #3
Source File: MavenHostedFacetImpl.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@TransactionalStoreBlob
protected int doRebuildArchetypeCatalog() throws IOException {
  final Path path = Files.createTempFile("hosted-archetype-catalog", "xml");
  int count = 0;
  try {
    StorageTx tx = UnitOfWork.currentTx();
    Iterable<Archetype> archetypes = getArchetypes(tx);
    ArchetypeCatalog hostedCatalog = new ArchetypeCatalog();
    Iterables.addAll(hostedCatalog.getArchetypes(), archetypes);
    count = hostedCatalog.getArchetypes().size();

    try (Content content = MavenFacetUtils.createTempContent(
        path,
        ContentTypes.APPLICATION_XML,
        (OutputStream outputStream) -> MavenModels.writeArchetypeCatalog(outputStream, hostedCatalog))) {
      MavenFacetUtils.putWithHashes(mavenFacet, archetypeCatalogMavenPath, content);
      log.trace("Rebuilt hosted archetype catalog for {} with {} archetype", getRepository().getName(), count);
    }
  }
  finally {
    Files.delete(path);
    
  }
  return count;
}
 
Example #4
Source File: MavenHostedFacetImpl.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the archetypes to publish for a hosted repository, the SELECT result count will be in parity with
 * published records count!
 */
protected Iterable<Archetype> getArchetypes(final StorageTx tx) throws IOException {
  Map<String, Object> sqlParams = new HashMap<>();
  sqlParams.put("bucket", AttachedEntityHelper.id(tx.findBucket(getRepository())));
  sqlParams.put("packaging", MAVEN_ARCHETYPE_PACKAGING);
  return transform(
      tx.browse(SELECT_HOSTED_ARCHETYPES, sqlParams),
      (ODocument document) -> {
        Archetype archetype = new Archetype();
        archetype.setGroupId(document.field("groupId", String.class));
        archetype.setArtifactId(document.field("artifactId", String.class));
        archetype.setVersion(document.field("version", String.class));
        archetype.setDescription(document.field("description", String.class));
        return archetype;
      }
  );
}
 
Example #5
Source File: ArchetypeCatalogMerger.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public boolean apply(final Archetype input) {
  String g = input.getGroupId();
  String a = input.getArtifactId();
  String v = input.getVersion();
  // G
  Map<String, Set<String>> aMap = gav.get(g);
  if (aMap == null) {
    aMap = new HashMap<>();
    gav.put(g, aMap);
  }
  // A
  Set<String> vSet = aMap.get(a);
  if (vSet == null) {
    vSet = new HashSet<>();
    aMap.put(a, vSet);
  }
  // V
  return vSet.add(v);
}
 
Example #6
Source File: FunktionArchetypeSelectionWizardStep.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
@Override
public Result execute(UIExecutionContext context) throws Exception {
    UIContext uiContext = context.getUIContext();
    Project project = (Project) uiContext.getAttributeMap().get(Project.class);
    Archetype chosenArchetype = archetype.getValue();
    String coordinate = chosenArchetype.getGroupId() + ":" + chosenArchetype.getArtifactId() + ":"
            + chosenArchetype.getVersion();
    DependencyQueryBuilder depQuery = DependencyQueryBuilder.create(coordinate);
    String repository = chosenArchetype.getRepository();
    if (!Strings.isNullOrEmpty(repository)) {
        if (repository.endsWith(".xml")) {
            int lastRepositoryPath = repository.lastIndexOf('/');
            if (lastRepositoryPath > -1)
                repository = repository.substring(0, lastRepositoryPath);
        }
        if (!repository.isEmpty()) {
            depQuery.setRepositories(new DependencyRepository("archetype", repository));
        }
    }
    Dependency resolvedArtifact = dependencyResolver.resolveArtifact(depQuery);
    FileResource<?> artifact = resolvedArtifact.getArtifact();
    MetadataFacet metadataFacet = project.getFacet(MetadataFacet.class);
    File fileRoot = project.getRoot().reify(DirectoryResource.class).getUnderlyingResourceObject();
    ArchetypeHelper archetypeHelper = new ArchetypeHelper(artifact.getResourceInputStream(), fileRoot,
            metadataFacet.getProjectGroupName(), metadataFacet.getProjectName(), metadataFacet.getProjectVersion());
    JavaSourceFacet facet = project.getFacet(JavaSourceFacet.class);
    archetypeHelper.setPackageName(facet.getBasePackage());
    archetypeHelper.execute();
    return Results.success();
}
 
Example #7
Source File: ArchetypeCatalogMerger.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Merges the contents of passed in catalogs
 */
public void merge(final OutputStream outputStream,
                  final MavenPath mavenPath,
                  final Map<Repository, Content> contents)
{
  log.debug("Merge archetype catalog for {}", mavenPath.getPath());
  ArchetypeCatalog mergedCatalog = new ArchetypeCatalog();
  UniqueFilter uniqueFilter = new UniqueFilter();

  try {
    for (Map.Entry<Repository, Content> entry : contents.entrySet()) {
      String origin = entry.getKey().getName() + " @ " + mavenPath.getPath();
      ArchetypeCatalog catalog = MavenModels.readArchetypeCatalog(entry.getValue().openInputStream());
      if (catalog == null) {
        log.debug("Corrupted archetype catalog: {}", origin);
        continue;
      }
      for (Archetype archetype : catalog.getArchetypes()) {
        if (uniqueFilter.apply(archetype)) {
          archetype.setRepository(null);
          mergedCatalog.addArchetype(archetype);
        }
      }
    }
    // sort the archetypes
    sortArchetypes(mergedCatalog);
    MavenModels.writeArchetypeCatalog(outputStream, mergedCatalog);
  }
  catch (IOException e) {
    log.error("Unable to merge {}", mavenPath, e);
  }
}
 
Example #8
Source File: ArchetypeCatalogMerger.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private void sortArchetypes(final ArchetypeCatalog mergedCatalog) {
  Collections.sort(mergedCatalog.getArchetypes(),
      (Archetype o1, Archetype o2) ->
      {
        int gc = o1.getGroupId().compareTo(o2.getGroupId());
        if (gc != 0) {
          return gc;
        }
        int ac = o1.getArtifactId().compareTo(o2.getArtifactId());
        if (ac != 0) {
          return ac;
        }
        return version(o1.getVersion()).compareTo(version(o2.getVersion()));
      });
}
 
Example #9
Source File: MavenArchetypeCatalogFacetImpl.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private Iterable<Archetype> getArchetypes() {
  List<Archetype> archetypes = new ArrayList<>();

  Continuation<FluentComponent> components =
      mavenContentFacet.components().browse(MAVEN_ARCHETYPE_KIND, componentPageSize, null);
  while (!components.isEmpty()) {
    archetypes.addAll(components.stream().map(this::toArchetype).collect(toList()));
    components = mavenContentFacet.
        components().browse(MAVEN_ARCHETYPE_KIND, componentPageSize, components.nextContinuationToken());
  }
  return archetypes;
}
 
Example #10
Source File: MavenArchetypeCatalogFacetImpl.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private Archetype toArchetype(final FluentComponent component) {
  Archetype archetype = new Archetype();
  archetype.setGroupId(component.namespace());
  archetype.setArtifactId(component.name());
  archetype.setVersion(component.version());
  return archetype;
}
 
Example #11
Source File: AdvancedSettingsComponent.java    From aem-eclipse-developer-tools with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("restriction")
void initialize() {
    if (propertiesTable == null) {
        return;
    }

    Archetype archetype = wizardPage.getChosenArchetype();
    if (archetype == null) {
        return;
    }

    try {
        ArchetypeManager archetypeManager = MavenPluginActivator
                .getDefault().getArchetypeManager();
        ArtifactRepository remoteArchetypeRepository = archetypeManager
                .getArchetypeRepository(archetype);
        properties.clear();
        for (RequiredProperty prop : (List<RequiredProperty>) archetypeManager
                .getRequiredProperties(archetype,
                        remoteArchetypeRepository, null)) {
        	properties.put(prop.getKey(), new RequiredPropertyWrapper(prop));
        }
        updateTable();
    } catch (Exception e) {
        throw new RuntimeException("Could not process archetype: "
                + e.getMessage(), e);
    }

}
 
Example #12
Source File: FunktionArchetypeSelectionWizardStep.java    From fabric8-forge with Apache License 2.0 4 votes vote down vote up
protected boolean isValidArchetype(Archetype archetype) {
    String artifactId = archetype.getArtifactId();
    return artifactId != null && artifactId.contains("funktion");
}
 
Example #13
Source File: SimplerParametersWizardPage.java    From aem-eclipse-developer-tools with Apache License 2.0 4 votes vote down vote up
public Archetype getChosenArchetype() {
    return chooseArchetypePage.getSelectedArchetype();
}
 
Example #14
Source File: NewGraniteProjectWizard.java    From aem-eclipse-developer-tools with Apache License 2.0 4 votes vote down vote up
@Override
public boolean acceptsArchetype(Archetype archetype2) {
	return (archetype2.getGroupId().startsWith("com.adobe.granite.archetypes"));
}