@Override public boolean handles(PackagingType packagingType) { return PackagingType.JAR.equals(packagingType); }
public static String toCanonicalForm(final Artifact artifact) { final StringBuilder sb = new StringBuilder(); sb.append(artifact.getGroupId()).append(":"); sb.append(artifact.getArtifactId()).append(":"); final PackagingType packaging = PackagingType .of(artifact.getProperty(ArtifactProperties.TYPE, artifact.getExtension())); final String classifier = artifact.getClassifier().length() == 0 ? packaging.getClassifier() : artifact.getClassifier(); sb.append(packaging.getId()).append(":"); if (classifier.length() != 0) { sb.append(classifier).append(":"); } sb.append(artifact.getVersion()); return sb.toString(); }
/** * Finds the first packaging processor on the classpath that supports give {@code packageType} * * @param packagingType Package type * @return */ @SuppressWarnings({ "rawtypes", "unchecked" }) public static PackagingProcessor<? extends Archive<?>> find( final PackagingType packagingType) { ServiceRegistry registry = ServiceRegistry.getInstance(); Collection<PackagingProcessor> processors = registry.all(PackagingProcessor.class); StringBuilder unsupportedFormatMessage = new StringBuilder("No packaging processor for ") .append(packagingType.toString()).append( " packaging was found. Supported processors are: "); for (PackagingProcessor processor : processors) { if (processor.handles(packagingType)) { // unchecked cast return (PackagingProcessor<? extends Archive<?>>) processor; } unsupportedFormatMessage.append(processor.getClass()).append(", "); } // trim if (unsupportedFormatMessage.indexOf(", ") != -1) { unsupportedFormatMessage.delete(unsupportedFormatMessage.length() - 2, unsupportedFormatMessage.length()); } throw new UnsupportedOperationException(unsupportedFormatMessage.toString()); }
/** * Builds a {@link PackagingType} object. * If an appropriate object is not found in a cache, then a new one is created and registered into the cache. * @see #fromCache(String) * * @param typeName * String name of the packaging type * @return Corresponding PackagingType object * @throws IllegalArgumentException * Thrown if typeName is {@code null} or empty */ public static PackagingType of(String typeName) throws IllegalArgumentException { PackagingType packagingType = fromCache(typeName); if (packagingType != null){ return packagingType; } // this will cause packaging object to register into cache return new PackagingType(typeName); }
protected MavenArtifactInfoImpl(final Artifact artifact, final ScopeType scopeType, final List<DependencyNode> children, boolean optional) { final PackagingType packaging = PackagingType.of(artifact.getProperty(ArtifactProperties.TYPE, artifact.getExtension())); final String classifier = artifact.getClassifier().length() == 0 ? packaging.getClassifier() : artifact.getClassifier(); this.mavenCoordinate = MavenCoordinates.createCoordinate(artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion(), packaging, classifier); this.resolvedVersion = artifact.getVersion(); this.snapshotVersion = artifact.isSnapshot(); this.extension = artifact.getExtension(); this.dependencies = parseDependencies(children); this.scopeType = scopeType; this.optional = optional; }
if (Validate.isNullOrEmptyOrQuestionMark(resolvedVersion) && dependency.getPackaging().equals(PackagingType.JAR) && dependency.getClassifier().equals(PackagingType.TEST_JAR.getClassifier())) { MavenCoordinate coordinate = MavenCoordinates.createCoordinate(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion(), PackagingType.TEST_JAR, PackagingType.TEST_JAR.getClassifier()); MavenDependency newDependency = new MavenDependencyImpl(coordinate, dependency.getScope(), dependency.isOptional(), dependency.getExclusions().toArray(new MavenDependencyExclusion[0]));
public static Artifact asArtifact(MavenCoordinate coordinate, ArtifactTypeRegistry registry) throws CoordinateParseException { try { return new DefaultArtifact(coordinate.getGroupId(), coordinate.getArtifactId(), coordinate.getClassifier(), coordinate.getPackaging().getExtension(), coordinate.getVersion(), registry.get(coordinate.getPackaging().getId())); } catch (IllegalArgumentException e) { throw new CoordinateParseException("Unable to create artifact from invalid coordinates " + coordinate.toCanonicalForm()); } }
private static PackagingType toPackagingType(final String type) { assert type != null : "Should not be fed a null type via internals (regardless of user input)"; PackagingType parsedPackagingType = null; try { parsedPackagingType = PackagingType.of(type); } catch (final IllegalArgumentException iae) { // Exception translate throw new CoordinateParseException(iae.getMessage()); } return parsedPackagingType; }
@Test public void ejbPackaging() { final String groupId = "groupId"; final String artifactId = "artifactId"; final PackagingType packaging = PackagingType.of("ejb"); final String version = "version"; final MavenCoordinate coordinate = new MavenCoordinateImpl(groupId, artifactId, version, packaging, null); Assert.assertEquals(PackagingType.EJB, coordinate.getPackaging()); Assert.assertEquals("jar", coordinate.getPackaging().getExtension()); } }
/** * Valid forms: <code>groupId:artifactId:packaging:classifier:version</code> * <code>groupId:artifactId:packaging:version</code> <code>groupId:artifactId:version</code> <code>groupId:artifactId</code> */ @Override public final String toCanonicalForm() { final StringBuilder sb = new StringBuilder(super.toCanonicalForm()); if (version == null || version.length() == 0) { return sb.toString(); } if (classifier != null && classifier.length() > 0 && packaging != null) { sb.append(SEPARATOR_COORDINATE).append(packaging.getId()).append(SEPARATOR_COORDINATE) .append(classifier).append(SEPARATOR_COORDINATE).append(version); } if ((classifier == null || classifier.length() == 0) && packaging != null) { sb.append(SEPARATOR_COORDINATE).append(packaging.getId()).append(SEPARATOR_COORDINATE).append(version); } return sb.toString(); }
tool.dependency(dep.getScope().name(), coord.getGroupId(), coord.getArtifactId(), coord.getVersion(), coord.getPackaging().getExtension(), coord.getClassifier(), dep.asFile(), topLevelDeps.contains(gav(coord))); tool.dependency(dep.getScope().name(), coord.getGroupId(), coord.getArtifactId(), coord.getVersion(), coord.getPackaging().getExtension(), coord.getClassifier(), dep.asFile(), this.requestedMavenArtifacts.contains(gav(coord)) || this.requestedMavenArtifacts.contains(ga(coord)));
private Class<? extends Archive> getIfSupported(File file) { String extension = FilenameUtils.getExtension(file.getName()); if (!Validate.isNullOrEmpty(extension)) { PackagingType packagingType = PackagingType.fromCache(extension); if (packagingType != null && packagingType != PackagingType.POM) { return getArchiveRepresentation(packagingType); } } return null; }
/** * Creates a new instance with the specified properties. <code>groupId</code> and <code>artifactId</code> are * required. If no {@link PackagingType} is specified, default will be to {@link PackagingType#JAR}. If no {@link ScopeType} * is specified, default will be {@link ScopeType#COMPILE}. * * @param groupId * @param artifactId * @param version * @param packaging * @param classifier */ MavenCoordinateImpl(final String groupId, final String artifactId, final String version, final PackagingType packaging, final String classifier) { // Precondition checks covered by superclass super(groupId, artifactId); // Set properties this.version = version; this.packaging = packaging == null ? PackagingType.JAR : packaging; // Adjust this for compatibility with Aether parser this.classifier = classifier == null ? packaging.getClassifier() : classifier; }
protected MavenArtifactInfoImpl(final Artifact artifact, final ScopeType scopeType, final List<DependencyNode> children, boolean optional) { final PackagingType packaging = PackagingType.of(artifact.getProperty(ArtifactProperties.TYPE, artifact.getExtension())); final String classifier = artifact.getClassifier().length() == 0 ? packaging.getClassifier() : artifact.getClassifier(); this.mavenCoordinate = MavenCoordinates.createCoordinate(artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion(), packaging, classifier); this.resolvedVersion = artifact.getVersion(); this.snapshotVersion = artifact.isSnapshot(); this.extension = artifact.getExtension(); this.dependencies = parseDependencies(children); this.scopeType = scopeType; this.optional = optional; }
if (Validate.isNullOrEmptyOrQuestionMark(resolvedVersion) && dependency.getPackaging().equals(PackagingType.JAR) && dependency.getClassifier().equals(PackagingType.TEST_JAR.getClassifier())) { MavenCoordinate coordinate = MavenCoordinates.createCoordinate(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion(), PackagingType.TEST_JAR, PackagingType.TEST_JAR.getClassifier()); MavenDependency newDependency = new MavenDependencyImpl(coordinate, dependency.getScope(), dependency.isOptional(), dependency.getExclusions().toArray(new MavenDependencyExclusion[0]));
public static Artifact asArtifact(MavenCoordinate coordinate, ArtifactTypeRegistry registry) throws CoordinateParseException { try { return new DefaultArtifact(coordinate.getGroupId(), coordinate.getArtifactId(), coordinate.getClassifier(), coordinate.getPackaging().getExtension(), coordinate.getVersion(), registry.get(coordinate.getPackaging().getId())); } catch (IllegalArgumentException e) { throw new CoordinateParseException("Unable to create artifact from invalid coordinates " + coordinate.toCanonicalForm()); } }
@Override public PackagingType getPackagingType() { return PackagingType.of(model.getPackaging()); }
@Override public Set<ArtifactSpec> resolveAll(final Set<ArtifactSpec> specs) { if (specs.isEmpty()) { return specs; } resetListeners(); final MavenResolvedArtifact[] artifacts = withResolver(r -> r.resolve(specs.stream().map(ArtifactSpec::mavenGav).collect(Collectors.toList())) .withTransitivity() .as(MavenResolvedArtifact.class)); return Arrays.stream(artifacts).map(artifact -> { final MavenCoordinate coord = artifact.getCoordinate(); return new ArtifactSpec("compile", coord.getGroupId(), coord.getArtifactId(), coord.getVersion(), coord.getPackaging().getId(), coord.getClassifier(), artifact.asFile()); }).collect(Collectors.toSet()); }
public Archive getDefaultBuiltArchive() { String finalName = getModel().getBuild().getFinalName(); String buildDirectory = getModel().getBuild().getDirectory(); String packaging = getModel().getPackaging(); PackagingType packagingType = PackagingType.fromCache(packaging); if (packagingType == null) { throw new IllegalArgumentException("The packaging type " + packaging + " is not supported"); } if (packagingType != PackagingType.POM) { File zipFile = new File(buildDirectory + File.separator + finalName + "." + packaging); return ShrinkWrap.createFromZipFile(getArchiveRepresentation(packagingType), zipFile); } else { return null; } }