use of org.jetbrains.idea.maven.model.MavenArtifact in project intellij-community by JetBrains.
the class ManifestImporter method getClasspath.
@NotNull
public String getClasspath(@NotNull MavenProject mavenProject, @Nullable Element manifestConfiguration) {
StringBuilder classpath = new StringBuilder();
String classpathPrefix = getClasspathPrefix(manifestConfiguration);
for (MavenArtifact mavenArtifact : mavenProject.getDependencies()) {
final DependencyScope scope = MavenModuleImporter.selectScope(mavenArtifact.getScope());
if (scope.isForProductionCompile() || scope.isForProductionRuntime()) {
if (classpath.length() > 0) {
classpath.append(" ");
}
classpath.append(classpathPrefix);
String artifactFileName = mavenArtifact.getArtifactId() + "-" + mavenArtifact.getVersion() + "." + mavenArtifact.getExtension();
classpath.append(doGetClasspathItem(mavenProject, mavenArtifact, artifactFileName));
}
}
return classpath.toString();
}
use of org.jetbrains.idea.maven.model.MavenArtifact in project intellij-community by JetBrains.
the class ArtifactsDownloadingTest method testDownloadingSpecificDependency.
public void testDownloadingSpecificDependency() throws Exception {
importProject("<groupId>test</groupId>" + "<artifactId>project</artifactId>" + "<version>1</version>" + "<dependencies>" + " <dependency>" + " <groupId>jmock</groupId>" + " <artifactId>jmock</artifactId>" + " <version>1.2.0</version>" + " </dependency>" + " <dependency>" + " <groupId>junit</groupId>" + " <artifactId>junit</artifactId>" + " <version>4.0</version>" + " </dependency>" + "</dependencies>");
File sources = new File(getRepositoryPath(), "/jmock/jmock/1.2.0/jmock-1.2.0-sources.jar");
File javadoc = new File(getRepositoryPath(), "/jmock/jmock/1.2.0/jmock-1.2.0-javadoc.jar");
assertFalse(sources.exists());
assertFalse(javadoc.exists());
MavenProject project = myProjectsTree.getRootProjects().get(0);
MavenArtifact dep = project.getDependencies().get(0);
downloadArtifacts(Arrays.asList(project), Arrays.asList(dep));
assertTrue(sources.exists());
assertTrue(javadoc.exists());
assertFalse(new File(getRepositoryPath(), "/junit/junit/4.0/junit-4.0-sources.jar").exists());
assertFalse(new File(getRepositoryPath(), "/junit/junit/4.0/junit-4.0-javadoc.jar").exists());
}
use of org.jetbrains.idea.maven.model.MavenArtifact in project intellij-community by JetBrains.
the class JUnit4IntegrationTest method before.
@Before
public void before() throws Throwable {
EdtTestUtil.runInEdtAndWait(() -> {
setUp();
Module module = createEmptyModule();
String communityPath = PlatformTestUtil.getCommunityPath().replace(File.separatorChar, '/');
String methodName = myNameRule.getMethodName();
methodName = methodName.substring(0, methodName.indexOf("["));
String testDataPath = communityPath + File.separator + "plugins" + File.separator + "junit5_rt_tests" + File.separator + "testData" + File.separator + "integration" + File.separator + methodName;
MavenId mavenId = new MavenId("junit", "junit", myJUnitVersion);
MavenRepositoryInfo repositoryInfo = new MavenRepositoryInfo("maven", "maven", "http://maven.labs.intellij.net/repo1");
RepositoryAttachHandler.doResolveInner(getProject(), mavenId, Collections.emptyList(), Collections.singleton(repositoryInfo), artifacts -> {
for (MavenArtifact artifact : artifacts) {
ModuleRootModificationUtil.addModuleLibrary(module, VfsUtilCore.pathToUrl(artifact.getPath()));
}
return true;
}, new DumbProgressIndicator());
ModuleRootModificationUtil.setModuleSdk(module, JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk());
ModuleRootModificationUtil.updateModel(module, model -> {
ContentEntry contentEntry = model.addContentEntry(VfsUtilCore.pathToUrl(testDataPath));
contentEntry.addSourceFolder(VfsUtilCore.pathToUrl(testDataPath + File.separator + "test"), true);
CompilerModuleExtension moduleExtension = model.getModuleExtension(CompilerModuleExtension.class);
moduleExtension.inheritCompilerOutputPath(false);
moduleExtension.setCompilerOutputPathForTests(VfsUtilCore.pathToUrl(testDataPath + File.separator + "out"));
});
});
}
use of org.jetbrains.idea.maven.model.MavenArtifact in project intellij-plugins by JetBrains.
the class ImporterUtil method postProcessAdditionalProperties.
/**
* Postprocessing step which handles Embed-Dependency and replaces placeholders on Import-Resources etc.
*/
static void postProcessAdditionalProperties(@NotNull Map<String, String> props, @NotNull MavenProject mavenProject, @NotNull Project project) {
Analyzer analyzer = new FakeAnalyzer(props);
Collection<MavenArtifact> dependencies = collectDependencies(props, mavenProject);
DependencyEmbedder embedder = new DependencyEmbedder(dependencies);
try {
embedder.processHeaders(analyzer);
} catch (DependencyEmbedderException e) {
String message = OsmorcBundle.message("maven.import.embed.error", mavenProject.getPath(), e.getMessage());
OsmorcProjectComponent.IMPORTANT_NOTIFICATIONS.createNotification(message, NotificationType.ERROR).notify(project);
}
ResourceCollector.includeMavenResources(mavenProject, analyzer);
// finally post-process the Include-Resources header to account for backslashes and relative paths
sanitizeIncludedResources(props, mavenProject);
}
use of org.jetbrains.idea.maven.model.MavenArtifact in project intellij-plugins by JetBrains.
the class ImporterUtil method collectDependencies.
/**
* Collects the dependencies for the given project. Takes into account any transitive embedding instructions.
*
* @param props the properties with additional instructions
* @param project the maven project
* @return a collection of dependencies.
*/
@NotNull
static Collection<MavenArtifact> collectDependencies(@NotNull Map<String, String> props, @NotNull MavenProject project) {
Collection<MavenArtifact> dependencies;
if (Boolean.parseBoolean(props.get(DependencyEmbedder.EMBED_TRANSITIVE))) {
Set<MavenArtifact> processed = new HashSet<>();
// flatten the tree while taking care of endless recursions
LinkedList<MavenArtifactNode> nodes = new LinkedList<>(project.getDependencyTree());
while (!nodes.isEmpty()) {
MavenArtifactNode node = nodes.pop();
MavenArtifact artifact = node.getArtifact();
if (!processed.contains(artifact)) {
processed.add(artifact);
nodes.addAll(node.getDependencies());
}
}
dependencies = processed;
} else {
dependencies = project.getDependencies();
}
return dependencies;
}
Aggregations