public boolean isSnapshot() { if (isSnapshot == null) { String version1 = getVersion(); final Matcher versionMatcher = snapshotPattern.matcher(version1); if (versionMatcher.find()) { isSnapshot = Boolean.TRUE; } else { isSnapshot = version1.contains("-SNAPSHOT"); } } return isSnapshot; }
public String relativeArtifactPath(char separator, String timestampVersion) { String artifactId1 = getArtifactId(); String version1 = getVersion(); StringBuilder builder = new StringBuilder(getGroupId().replace('.', separator)); builder.append(separator).append(artifactId1).append(separator); String pathVersion; final Matcher versionMatcher = snapshotPattern.matcher(version1); if (versionMatcher.find()) { // it's really a snapshot pathVersion = version1.substring(0, versionMatcher.start()) + "-SNAPSHOT"; } else { pathVersion = version1; } builder.append(pathVersion).append(separator).append(artifactId1).append('-').append(timestampVersion); return builder.toString(); }
public String relativeMetadataPath(char separator) { String artifactId1 = getArtifactId(); String version1 = getVersion(); StringBuilder builder = new StringBuilder(getGroupId().replace('.', separator)); builder.append(separator).append(artifactId1).append(separator); String pathVersion; final Matcher versionMatcher = snapshotPattern.matcher(version1); if (versionMatcher.find()) { // it's really a snapshot pathVersion = version1.substring(0, versionMatcher.start()) + "-SNAPSHOT"; } else { pathVersion = version1; } builder.append(pathVersion).append(separator).append("maven-metadata.xml"); return builder.toString(); }
/** * Create a relative repository path for the given artifact coordinates. * * @param separator the separator character to use (typically {@code '/'} or {@link File#separatorChar}) * @return the path string */ public String relativeArtifactPath(char separator) { String artifactId1 = getArtifactId(); String version1 = getVersion(); StringBuilder builder = new StringBuilder(getGroupId().replace('.', separator)); builder.append(separator).append(artifactId1).append(separator); String pathVersion; final Matcher versionMatcher = snapshotPattern.matcher(version1); if (versionMatcher.find()) { // it's really a snapshot pathVersion = version1.substring(0, versionMatcher.start()) + "-SNAPSHOT"; } else { pathVersion = version1; } builder.append(pathVersion).append(separator).append(artifactId1).append('-').append(version1); return builder.toString(); }
/** * Create a relative repository path for the given artifact coordinates. * * @param separator the separator character to use (typically {@code '/'} or {@link File#separatorChar}) * @return the path string */ public String relativeArtifactPath(char separator) { String artifactId1 = getArtifactId(); String version1 = getVersion(); StringBuilder builder = new StringBuilder(getGroupId().replace('.', separator)); builder.append(separator).append(artifactId1).append(separator); String pathVersion; final Matcher versionMatcher = snapshotPattern.matcher(version1); if (versionMatcher.find()) { // it's really a snapshot pathVersion = version1.substring(0, versionMatcher.start()) + "-SNAPSHOT"; } else { pathVersion = version1; } builder.append(pathVersion).append(separator).append(artifactId1).append('-').append(version1); return builder.toString(); }
/** * Build file name for artifact. * * @param artifactCoordinates * @param packaging * @return */ String toGradleArtifactFileName(ArtifactCoordinates artifactCoordinates, String packaging) { StringBuilder sbFileFilter = new StringBuilder(); sbFileFilter .append(artifactCoordinates.getArtifactId()) .append("-") .append(artifactCoordinates.getVersion()); if (artifactCoordinates.getClassifier() != null && artifactCoordinates.getClassifier().length() > 0) { sbFileFilter .append("-") .append(artifactCoordinates.getClassifier()); } sbFileFilter .append(".") .append(packaging); return sbFileFilter.toString(); }
@Override public File resolveArtifact(ArtifactCoordinates artifactCoordinates, String packaging) throws IOException { //Search the matching artifact in a gradle cache. String filter = toGradleArtifactFileName(artifactCoordinates, packaging); Path artifactDirectory = Paths.get(gradleCachePath, artifactCoordinates.getGroupId(), artifactCoordinates.getArtifactId(), artifactCoordinates.getVersion()); if (Files.exists(artifactDirectory)) { File latestArtifactFile = null; for (Path hashDir : Files.list(artifactDirectory).collect(Collectors.toList())) { for (Path artifact : Files.list(hashDir).collect(Collectors.toList())) { if (artifact.endsWith(filter)) { File artifactFile = artifact.toFile(); if (latestArtifactFile == null || latestArtifactFile.lastModified() < artifactFile.lastModified()) { //take always the latest version of the artifact latestArtifactFile = artifactFile; } } } } if (latestArtifactFile != null) { return latestArtifactFile; } } //Artifact not found in the locale gradle cache. Try to resolve it from the remote respository return downloadFromRemoteRepository(artifactCoordinates, packaging, artifactDirectory); }
@Override public File resolveArtifact(ArtifactCoordinates coordinates, String packaging) throws IOException { String artifactRelativePath = "m2repo/" + relativeArtifactPath('/', coordinates.getGroupId(), coordinates.getArtifactId(), coordinates.getVersion()); String classifier = ""; if (coordinates.getClassifier() != null && !coordinates.getClassifier().trim().isEmpty()) { classifier = "-" + coordinates.getClassifier(); } String jarPath = artifactRelativePath + classifier + "." + packaging; InputStream stream = UberJarMavenResolver.class.getClassLoader().getResourceAsStream(jarPath); if (stream != null) { return copyTempJar(coordinates.getArtifactId() + "-" + coordinates.getVersion(), stream, packaging); } return null; } }
@Override public File resolveArtifact(ArtifactCoordinates coordinates, String packaging) throws IOException { File resolved = this.resolutionCache.get(coordinates); if (resolved == null) { String artifactRelativePath = "m2repo/" + relativeArtifactPath('/', coordinates.getGroupId(), coordinates.getArtifactId(), coordinates.getVersion()); String classifier = ""; if (coordinates.getClassifier() != null && !coordinates.getClassifier().trim().isEmpty()) { classifier = HYPHEN + coordinates.getClassifier(); } String jarPath = artifactRelativePath + classifier + DOT + packaging; InputStream stream = UberJarMavenResolver.class.getClassLoader().getResourceAsStream(jarPath); if (stream != null) { try { resolved = copyTempJar(coordinates.getArtifactId() + HYPHEN + coordinates.getVersion(), stream, packaging); this.resolutionCache.put(coordinates, resolved); } finally { stream.close(); } } } return resolved; }
final String version = coordinates.getVersion(); try { return Version.parse(version);