Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#4554 fix Class not found exception in maven server #4613

Merged
merged 1 commit into from
Mar 31, 2017
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 @@ -45,6 +45,7 @@

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
Expand Down Expand Up @@ -124,6 +125,27 @@ public void testDownloadSources() throws Exception {
assertTrue(downloadSources);
}

@Test
public void testDownloadSourcesLog4j() throws Exception {
String pom = "<groupId>test</groupId>" +
"<artifactId>testArtifact</artifactId>" +
"<version>42</version>" +
"<dependencies>" +
" <dependency>" +
" <groupId>log4j</groupId>" +
" <artifactId>log4j</artifactId>" +
" <version>1.2.12</version>" +
" </dependency>" +
"</dependencies>";
createTestProject("test", pom);

IProject test = ResourcesPlugin.getWorkspace().getRoot().getProject("test");
mavenWorkspace.update(Collections.singletonList(test));
mavenWorkspace.waitForUpdate();
boolean downloadSources = classpathManager.downloadSources(test.getFullPath().toOSString(), "org.apache.log4j.Logger");
assertFalse(downloadSources);
}

@Test
public void testDownloadedSourcesShouldAttachToPackageFragmentRoot() throws Exception {
String pom = "<groupId>test</groupId>" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,9 @@ public MavenArtifact resolveArtifact(MavenArtifactKey artifactKey, List<MavenRem
new ArtifactRequest(RepositoryUtils.toArtifact(artifact),
remoteRepositories, null));
return MavenModelUtil.convertArtifact(RepositoryUtils.toArtifact(artifactResult.getArtifact()), localRepository);
} catch (ArtifactResolutionException e) {
MavenServerContext.getLogger().info(e);
} catch (ArtifactResolutionException ignored) {
//we need ignore exception, it's some times has class that client doesn't has
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may be system.error.println()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All sdtout/stderr of the maven sever is logged by client, but 'ArtifactResolutionException' is normal when maven can't find or download artifact, so I not sure that this exception need to be logged.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

up2you

// .printStackTrace() may be solution, but it will spam wsagent logs
}
return MavenModelUtil.convertArtifact(artifact, localRepository);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,19 @@ public void setUp() throws Exception {

@Override
public void warning(Throwable t) throws RemoteException {
t.printStackTrace();
}

@Override
public void info(Throwable t) throws RemoteException {
t.printStackTrace();
}

@Override
public void error(Throwable t) throws RemoteException {
t.printStackTrace();
}
}, (file, relativePath) -> {
System.out.println(file.getAbsolutePath());
});
}, (file, relativePath) -> System.out.println(file.getAbsolutePath()));
MavenSettings mavenSettings = new MavenSettings();
mavenSettings.setLoggingLevel(MavenTerminal.LEVEL_INFO);
mavenSettings.setMavenHome(new File(System.getenv("M2_HOME")));
Expand All @@ -69,7 +70,6 @@ public void error(Throwable t) throws RemoteException {
}, new MavenServerProgressNotifier() {
@Override
public void setText(String text) throws RemoteException {
System.out.println(text);
}

@Override
Expand Down Expand Up @@ -144,6 +144,14 @@ public void testResolveArtifactSource() throws Exception {
assertTrue(artifact.isResolved());
}

@Test
public void testResolveLog4jSource() throws Exception {
MavenArtifactKey artifactKey = new MavenArtifactKey("log4j", "log4j", "1.2.12", "jar", "sources");
MavenArtifact artifact = mavenServer.resolveArtifact(artifactKey, Collections.emptyList());
assertNotNull(artifact);
assertFalse(artifact.isResolved());
}

@Test
public void testResolveNotExistingArtifact() throws Exception {
MavenArtifactKey artifactKey = new MavenArtifactKey("junit", "junit", "3.56", "jar", "");
Expand Down