Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@
package org.apache.storm.submit.command;

import com.google.common.base.Preconditions;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
Expand All @@ -33,6 +32,7 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import net.minidev.json.JSONValue;

Expand Down Expand Up @@ -70,7 +70,7 @@ public class DependencyResolverMain {
* @throws ParseException If there's parsing error on option parse.
* @throws MalformedURLException If proxy URL is malformed.
*/
public static void main(String[] args) throws ParseException, MalformedURLException {
public static void main(String[] args) throws ParseException, MalformedURLException, URISyntaxException {
Options options = buildOptions();
CommandLineParser parser = new DefaultParser();
CommandLine commandLine = parser.parse(options, args);
Expand Down Expand Up @@ -117,28 +117,21 @@ public static void main(String[] args) throws ParseException, MalformedURLExcept

List<ArtifactResult> artifactResults = resolver.resolve(dependencies);

Iterable<ArtifactResult> missingArtifacts = filterMissingArtifacts(artifactResults);
if (missingArtifacts.iterator().hasNext()) {
List<ArtifactResult> missingArtifacts = artifactResults.stream()
.filter(ArtifactResult::isMissing)
.collect(Collectors.toList());
if (!missingArtifacts.isEmpty()) {
printMissingArtifactsToSysErr(missingArtifacts);
throw new RuntimeException("Some artifacts are not resolved");
}

System.out.println(JSONValue.toJSONString(transformArtifactResultToArtifactToPaths(artifactResults)));
System.out.flush();
} catch (Throwable e) {
} catch (Exception e) {
throw new RuntimeException(e);
}
}

private static Iterable<ArtifactResult> filterMissingArtifacts(List<ArtifactResult> artifactResults) {
return Iterables.filter(artifactResults, new Predicate<ArtifactResult>() {
@Override
public boolean apply(ArtifactResult artifactResult) {
return artifactResult.isMissing();
}
});
}

private static void printMissingArtifactsToSysErr(Iterable<ArtifactResult> missingArtifacts) {
for (ArtifactResult artifactResult : missingArtifacts) {
System.err.println("ArtifactResult : " + artifactResult + " / Errors : " + artifactResult.getExceptions());
Expand Down Expand Up @@ -173,14 +166,15 @@ private static List<RemoteRepository> parseRemoteRepositoryArgs(String remoteRep
return remoteRepositories;
}

private static Proxy parseProxyArg(String proxyUrl, String proxyUsername, String proxyPassword) throws MalformedURLException {
URL url = new URL(proxyUrl);
private static Proxy parseProxyArg(String proxyUrl, String proxyUsername, String proxyPassword)
throws MalformedURLException, URISyntaxException {
URI uri = new URI(proxyUrl);
if (StringUtils.isNotEmpty(proxyUsername) && StringUtils.isNotEmpty(proxyPassword)) {
AuthenticationBuilder authBuilder = new AuthenticationBuilder();
authBuilder.addUsername(proxyUsername).addPassword(proxyPassword);
return new Proxy(url.getProtocol(), url.getHost(), url.getPort(), authBuilder.build());
return new Proxy(uri.getScheme(), uri.getHost(), uri.getPort(), authBuilder.build());
} else {
return new Proxy(url.getProtocol(), url.getHost(), url.getPort());
return new Proxy(uri.getScheme(), uri.getHost(), uri.getPort());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,23 @@
import org.eclipse.aether.repository.LocalRepository;
import org.eclipse.aether.repository.RemoteRepository;

/**
* Manage mvn repository.
*/
public class Booter {
public final class Booter {
private Booter() {
}

public static RepositorySystem newRepositorySystem() {
return RepositorySystemFactory.newRepositorySystem();
}

public static RepositorySystemSession newRepositorySystemSession(
RepositorySystem system, String localRepoPath) {
DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();

LocalRepository localRepo =
new LocalRepository(new File(localRepoPath).getAbsolutePath());
LocalRepository localRepo = new LocalRepository(new File(localRepoPath).getAbsolutePath());
session.setLocalRepositoryManager(system.newLocalRepositoryManager(session, localRepo));

return session;
}

public static RemoteRepository newCentralRepository() {
return new RemoteRepository.Builder("central", "default", "https://repo1.maven.org/maven2/").build();
}

public static RemoteRepository newLocalRepository() {
return new RemoteRepository.Builder("local",
"default", "file://" + System.getProperty("user.home") + "/.m2/repository").build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,12 @@ private String handleRelativePath(String localRepoPath) {
public List<ArtifactResult> resolve(List<Dependency> dependencies) throws
DependencyResolutionException, ArtifactResolutionException {

if (dependencies.size() == 0) {
return Collections.EMPTY_LIST;
if (dependencies.isEmpty()) {
return Collections.emptyList();
}

CollectRequest collectRequest = new CollectRequest();
collectRequest.setRoot(dependencies.get(0));
for (int idx = 1; idx < dependencies.size(); idx++) {
collectRequest.addDependency(dependencies.get(idx));
}
collectRequest.setDependencies(dependencies);

for (RemoteRepository repository : remoteRepositories) {
collectRequest.addRepository(repository);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
import org.eclipse.aether.transport.file.FileTransporterFactory;
import org.eclipse.aether.transport.http.HttpTransporterFactory;

/**
* Get maven repository instance.
*/
public class RepositorySystemFactory {
public final class RepositorySystemFactory {
private RepositorySystemFactory() {
}

public static RepositorySystem newRepositorySystem() {
DefaultServiceLocator locator = MavenRepositorySystemUtils.newServiceLocator();
locator.addService(RepositoryConnectorFactory.class, BasicRepositoryConnectorFactory.class);
Expand All @@ -47,5 +47,4 @@ public void serviceCreationFailed(Class<?> type, Class<?> impl, Throwable except

return locator.getService(RepositorySystem.class);
}

}
Loading