mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-25146 Maven integration, resolve dependencies from project
This commit is contained in:
@@ -252,6 +252,17 @@ public def layoutCommunityPlugins(String home) {
|
||||
module("maven3-server-impl")
|
||||
}
|
||||
|
||||
jar("artifact-resolver-m2.jar") {
|
||||
module("maven-artifact-resolver-m2")
|
||||
}
|
||||
|
||||
jar("artifact-resolver-m3.jar") {
|
||||
module("maven-artifact-resolver-m3")
|
||||
module("maven-artifact-resolver-m2") {
|
||||
include(name: 'org/jetbrains/idea/maven/artifactResolver/common/*')
|
||||
}
|
||||
}
|
||||
|
||||
dir("maven3") {
|
||||
fileset(dir: "$home/plugins/maven/maven3-server-impl/lib") {include(name: "*.jar")}
|
||||
fileset(dir: "$home/plugins/maven/maven3-server-impl/lib/maven3/lib") {include(name: "*.jar")}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/../workspace-resolver-m2/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="Maven2" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
<component-set>
|
||||
<components>
|
||||
<component>
|
||||
<role>org.apache.maven.artifact.resolver.ArtifactResolver</role>
|
||||
<implementation>org.jetbrains.idea.maven.artifactResolver.MyArtifactResolver</implementation>
|
||||
<requirements>
|
||||
<requirement>
|
||||
<role>org.apache.maven.artifact.manager.WagonManager</role>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.artifact.transform.ArtifactTransformationManager</role>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.artifact.factory.ArtifactFactory</role>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.artifact.resolver.ArtifactCollector</role>
|
||||
</requirement>
|
||||
</requirements>
|
||||
</component>
|
||||
</components>
|
||||
</component-set>
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jetbrains.idea.maven.artifactResolver;
|
||||
|
||||
/**
|
||||
* @author Sergey Evdokimov
|
||||
*/
|
||||
public class MavenArtifactResolvedM2RtMarker {
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jetbrains.idea.maven.artifactResolver;
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
||||
import org.apache.maven.artifact.resolver.DefaultArtifactResolver;
|
||||
import org.jetbrains.idea.maven.artifactResolver.common.MavenModuleMap;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Sergey Evdokimov
|
||||
*/
|
||||
public class MyArtifactResolver extends DefaultArtifactResolver {
|
||||
|
||||
@Override
|
||||
public void resolve(Artifact artifact, List remoteRepositories, ArtifactRepository localRepository)
|
||||
throws ArtifactResolutionException, ArtifactNotFoundException {
|
||||
if (!MavenModuleMap.getInstance().resolveToModule(artifact)) {
|
||||
super.resolve(artifact, remoteRepositories, localRepository);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resolveAlways(Artifact artifact, List remoteRepositories, ArtifactRepository localRepository)
|
||||
throws ArtifactResolutionException, ArtifactNotFoundException {
|
||||
if (!MavenModuleMap.getInstance().resolveToModule(artifact)) {
|
||||
super.resolveAlways(artifact, remoteRepositories, localRepository);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jetbrains.idea.maven.artifactResolver.common;
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* @author Sergey Evdokimov
|
||||
*/
|
||||
public class MavenModuleMap {
|
||||
|
||||
private static final MavenModuleMap ourInstance = new MavenModuleMap();
|
||||
|
||||
public static final String PATHS_FILE_PROPERTY = "idea.modules.paths.file";
|
||||
|
||||
private final Properties myMap = new Properties();
|
||||
|
||||
private MavenModuleMap() {
|
||||
String path = System.getProperty(PATHS_FILE_PROPERTY);
|
||||
if(path != null) {
|
||||
try {
|
||||
BufferedInputStream in = new BufferedInputStream(new FileInputStream(path));
|
||||
try {
|
||||
myMap.load(in);
|
||||
} finally {
|
||||
in.close();
|
||||
}
|
||||
} catch(IOException e) {
|
||||
// XXX log
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static MavenModuleMap getInstance() {
|
||||
return ourInstance;
|
||||
}
|
||||
|
||||
public boolean resolveToModule(Artifact artifact) {
|
||||
String extension = artifact.getArtifactHandler().getExtension();
|
||||
File file = findArtifact(artifact.getGroupId(), artifact.getArtifactId(), extension, artifact.getBaseVersion());
|
||||
|
||||
if(file == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
artifact.setFile(file);
|
||||
artifact.setResolved(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
public File findArtifact(String groupId, String artifactId, String type, String baseVersion) {
|
||||
String key = groupId + ':' + artifactId + ':' + type + ':' + baseVersion;
|
||||
String value = myMap.getProperty(key);
|
||||
|
||||
if(value == null || value.length() == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
File file = new File(value);
|
||||
if(!file.exists()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/../workspace-resolver-m3/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="Maven3" level="project" />
|
||||
<orderEntry type="module" module-name="maven-artifact-resolver-m2" exported="" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<component-set>
|
||||
<components>
|
||||
<component>
|
||||
<role>org.apache.maven.repository.LocalArtifactRepository</role>
|
||||
<role-hint>ide-workspace</role-hint>
|
||||
<implementation>org.jetbrains.idea.maven.artifactResolver.MyArtifactRepository</implementation>
|
||||
<description />
|
||||
<isolated-realm>false</isolated-realm>
|
||||
</component>
|
||||
<component>
|
||||
<role>org.sonatype.aether.repository.WorkspaceReader</role>
|
||||
<role-hint>ide</role-hint>
|
||||
<implementation>org.jetbrains.idea.maven.artifactResolver.MyWorkspaceReader</implementation>
|
||||
<description />
|
||||
<isolated-realm>false</isolated-realm>
|
||||
</component>
|
||||
</components>
|
||||
</component-set>
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jetbrains.idea.maven.artifactResolver;
|
||||
|
||||
/**
|
||||
* @author Sergey Evdokimov
|
||||
*/
|
||||
public class MavenArtifactResolvedM3RtMarker {
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jetbrains.idea.maven.artifactResolver;
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.repository.LocalArtifactRepository;
|
||||
import org.jetbrains.idea.maven.artifactResolver.common.MavenModuleMap;
|
||||
|
||||
/**
|
||||
* @author Sergey Evdokimov
|
||||
*/
|
||||
public class MyArtifactRepository extends LocalArtifactRepository {
|
||||
|
||||
protected boolean resolveAsModule(Artifact artifact) {
|
||||
if (artifact == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return MavenModuleMap.getInstance().resolveToModule(artifact);
|
||||
}
|
||||
|
||||
public Artifact find(Artifact artifact) {
|
||||
resolveAsModule(artifact);
|
||||
return artifact;
|
||||
}
|
||||
|
||||
public boolean hasLocalMetadata() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof MyArtifactRepository;
|
||||
}
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jetbrains.idea.maven.artifactResolver;
|
||||
|
||||
import org.codehaus.plexus.component.annotations.Component;
|
||||
import org.jetbrains.idea.maven.artifactResolver.common.MavenModuleMap;
|
||||
import org.sonatype.aether.artifact.Artifact;
|
||||
import org.sonatype.aether.repository.WorkspaceReader;
|
||||
import org.sonatype.aether.repository.WorkspaceRepository;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Sergey Evdokimov
|
||||
*/
|
||||
@Component(role = WorkspaceReader.class, hint = "ide")
|
||||
public class MyWorkspaceReader implements WorkspaceReader {
|
||||
|
||||
private final WorkspaceRepository myWorkspaceRepository;
|
||||
|
||||
public MyWorkspaceReader() {
|
||||
myWorkspaceRepository = new WorkspaceRepository("ide", getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof MyWorkspaceReader;
|
||||
}
|
||||
|
||||
public WorkspaceRepository getRepository() {
|
||||
return myWorkspaceRepository;
|
||||
}
|
||||
|
||||
public File findArtifact(Artifact artifact) {
|
||||
return MavenModuleMap.getInstance().findArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getExtension(),
|
||||
artifact.getBaseVersion());
|
||||
}
|
||||
|
||||
public List<String> findVersions(Artifact artifact) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -58,6 +58,7 @@
|
||||
<orderEntry type="module" module-name="lang-impl" />
|
||||
<orderEntry type="module" module-name="jps-model-impl" />
|
||||
<orderEntry type="module" module-name="maven-jps-plugin" />
|
||||
<orderEntry type="module" module-name="maven-artifact-resolver-m3" />
|
||||
</component>
|
||||
<component name="copyright">
|
||||
<Base>
|
||||
|
||||
@@ -28,48 +28,6 @@
|
||||
<SOURCES />
|
||||
</library>
|
||||
</orderEntry>
|
||||
<orderEntry type="module-library">
|
||||
<library name="Maven">
|
||||
<CLASSES>
|
||||
<root url="jar://$MODULE_DIR$/lib/maven-dependency-tree-1.2.jar!/" />
|
||||
<root url="jar://$MODULE_DIR$/lib/archetype-common-2.0-alpha-4-SNAPSHOT.jar!/" />
|
||||
<root url="jar://$MODULE_DIR$/lib/mercury-artifact-1.0-alpha-6.jar!/" />
|
||||
<root url="jar://$MODULE_DIR$/lib/maven-2.2.1-uber.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
<root url="jar://$MODULE_DIR$/lib-src/apache-maven-2.2.1-src.zip!/apache-maven-2.2.1/maven-artifact-test/src/main/java" />
|
||||
<root url="jar://$MODULE_DIR$/lib-src/apache-maven-2.2.1-src.zip!/apache-maven-2.2.1/maven-project/src/test/java" />
|
||||
<root url="jar://$MODULE_DIR$/lib-src/apache-maven-2.2.1-src.zip!/apache-maven-2.2.1/maven-settings/src/test/java" />
|
||||
<root url="jar://$MODULE_DIR$/lib-src/apache-maven-2.2.1-src.zip!/apache-maven-2.2.1/maven-core/src/test/java" />
|
||||
<root url="jar://$MODULE_DIR$/lib-src/apache-maven-2.2.1-src.zip!/apache-maven-2.2.1/maven-plugin-descriptor/src/test/java" />
|
||||
<root url="jar://$MODULE_DIR$/lib-src/apache-maven-2.2.1-src.zip!/apache-maven-2.2.1/maven-plugin-api/src/main/java" />
|
||||
<root url="jar://$MODULE_DIR$/lib-src/apache-maven-2.2.1-src.zip!/apache-maven-2.2.1/maven-artifact-manager/src/main/java" />
|
||||
<root url="jar://$MODULE_DIR$/lib-src/apache-maven-2.2.1-src.zip!/apache-maven-2.2.1/maven-plugin-descriptor/src/main/java" />
|
||||
<root url="jar://$MODULE_DIR$/lib-src/apache-maven-2.2.1-src.zip!/apache-maven-2.2.1/maven-script/maven-script-beanshell/src/main/java" />
|
||||
<root url="jar://$MODULE_DIR$/lib-src/apache-maven-2.2.1-src.zip!/apache-maven-2.2.1/maven-error-diagnostics/src/main/java" />
|
||||
<root url="jar://$MODULE_DIR$/lib-src/apache-maven-2.2.1-src.zip!/apache-maven-2.2.1/maven-plugin-parameter-documenter/src/test/java" />
|
||||
<root url="jar://$MODULE_DIR$/lib-src/apache-maven-2.2.1-src.zip!/apache-maven-2.2.1/maven-settings/src/main/java" />
|
||||
<root url="jar://$MODULE_DIR$/lib-src/apache-maven-2.2.1-src.zip!/apache-maven-2.2.1/maven-model/src/test/java" />
|
||||
<root url="jar://$MODULE_DIR$/lib-src/apache-maven-2.2.1-src.zip!/apache-maven-2.2.1/maven-plugin-registry/src/main/java" />
|
||||
<root url="jar://$MODULE_DIR$/lib-src/apache-maven-2.2.1-src.zip!/apache-maven-2.2.1/maven-artifact/src/test/java" />
|
||||
<root url="jar://$MODULE_DIR$/lib-src/apache-maven-2.2.1-src.zip!/apache-maven-2.2.1/maven-core-it-runner/src/test/java" />
|
||||
<root url="jar://$MODULE_DIR$/lib-src/apache-maven-2.2.1-src.zip!/apache-maven-2.2.1/maven-core/src/main/java" />
|
||||
<root url="jar://$MODULE_DIR$/lib-src/apache-maven-2.2.1-src.zip!/apache-maven-2.2.1/maven-artifact-manager/src/test/java" />
|
||||
<root url="jar://$MODULE_DIR$/lib-src/apache-maven-2.2.1-src.zip!/apache-maven-2.2.1/maven-toolchain/src/test/java" />
|
||||
<root url="jar://$MODULE_DIR$/lib-src/apache-maven-2.2.1-src.zip!/apache-maven-2.2.1/maven-monitor/src/main/java" />
|
||||
<root url="jar://$MODULE_DIR$/lib-src/apache-maven-2.2.1-src.zip!/apache-maven-2.2.1/maven-artifact/src/main/java" />
|
||||
<root url="jar://$MODULE_DIR$/lib-src/apache-maven-2.2.1-src.zip!/apache-maven-2.2.1/maven-compat/src/main/java" />
|
||||
<root url="jar://$MODULE_DIR$/lib-src/apache-maven-2.2.1-src.zip!/apache-maven-2.2.1/maven-script/maven-script-ant/src/main/java" />
|
||||
<root url="jar://$MODULE_DIR$/lib-src/apache-maven-2.2.1-src.zip!/apache-maven-2.2.1/maven-script/maven-script-ant/src/test/java" />
|
||||
<root url="jar://$MODULE_DIR$/lib-src/apache-maven-2.2.1-src.zip!/apache-maven-2.2.1/maven-toolchain/src/main/java" />
|
||||
<root url="jar://$MODULE_DIR$/lib-src/apache-maven-2.2.1-src.zip!/apache-maven-2.2.1/maven-reporting/maven-reporting-api/src/main/java" />
|
||||
<root url="jar://$MODULE_DIR$/lib-src/apache-maven-2.2.1-src.zip!/apache-maven-2.2.1/apache-maven/src/test/java" />
|
||||
<root url="jar://$MODULE_DIR$/lib-src/apache-maven-2.2.1-src.zip!/apache-maven-2.2.1/maven-project/src/main/java" />
|
||||
<root url="jar://$MODULE_DIR$/lib-src/apache-maven-2.2.1-src.zip!/apache-maven-2.2.1/maven-profile/src/main/java" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</orderEntry>
|
||||
<orderEntry type="module-library">
|
||||
<library>
|
||||
<CLASSES>
|
||||
@@ -101,6 +59,7 @@
|
||||
</library>
|
||||
</orderEntry>
|
||||
<orderEntry type="module" module-name="maven" scope="TEST" />
|
||||
<orderEntry type="library" name="Maven2" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
|
||||
@@ -149,6 +149,7 @@
|
||||
<SOURCES />
|
||||
</library>
|
||||
</orderEntry>
|
||||
<orderEntry type="library" name="Maven3" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
|
||||
+144
-9
@@ -25,6 +25,8 @@ import com.intellij.execution.configurations.ParametersList;
|
||||
import com.intellij.execution.impl.EditConfigurationsDialog;
|
||||
import com.intellij.execution.impl.RunManagerImpl;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.options.ShowSettingsUtil;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.projectRoots.JavaSdk;
|
||||
@@ -33,29 +35,37 @@ import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.projectRoots.impl.JavaAwareProjectJdkTableImpl;
|
||||
import com.intellij.openapi.roots.ProjectRootManager;
|
||||
import com.intellij.openapi.roots.ui.configuration.ProjectSettingsService;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.encoding.EncodingManager;
|
||||
import com.intellij.openapi.vfs.encoding.EncodingProjectManager;
|
||||
import com.intellij.util.PathUtil;
|
||||
import com.intellij.util.io.ZipUtil;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.idea.maven.artifactResolver.MavenArtifactResolvedM2RtMarker;
|
||||
import org.jetbrains.idea.maven.artifactResolver.MavenArtifactResolvedM3RtMarker;
|
||||
import org.jetbrains.idea.maven.artifactResolver.common.MavenModuleMap;
|
||||
import org.jetbrains.idea.maven.project.MavenGeneralSettings;
|
||||
import org.jetbrains.idea.maven.project.MavenProject;
|
||||
import org.jetbrains.idea.maven.project.MavenProjectsManager;
|
||||
import org.jetbrains.idea.maven.utils.MavenSettings;
|
||||
import org.jetbrains.idea.maven.utils.MavenUtil;
|
||||
|
||||
import javax.swing.event.HyperlinkEvent;
|
||||
import javax.swing.event.HyperlinkListener;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
/**
|
||||
* @author Ralf Quebbemann
|
||||
*/
|
||||
public class MavenExternalParameters {
|
||||
|
||||
private static final Logger LOG = Logger.getInstance(MavenExternalParameters.class);
|
||||
|
||||
public static final String MAVEN_LAUNCHER_CLASS = "org.codehaus.classworlds.Launcher";
|
||||
@NonNls private static final String JAVA_HOME = "JAVA_HOME";
|
||||
@NonNls private static final String MAVEN_OPTS = "MAVEN_OPTS";
|
||||
@@ -107,6 +117,27 @@ public class MavenExternalParameters {
|
||||
|
||||
addVMParameters(params.getVMParametersList(), mavenHome, runnerSettings);
|
||||
|
||||
File confFile = MavenUtil.getMavenConfFile(new File(mavenHome));
|
||||
if (!confFile.isFile()) {
|
||||
throw new ExecutionException("Configuration file is not exists in maven home: " + confFile.getAbsolutePath());
|
||||
}
|
||||
|
||||
if (project != null && parameters.isResolveToWorkspace()) {
|
||||
try {
|
||||
String resolverJar = getArtifactResolverJar(MavenUtil.isMaven3(mavenHome));
|
||||
confFile = patchConfFile(confFile, resolverJar);
|
||||
|
||||
File modulesPathsFile = dumpModulesPaths(project);
|
||||
params.getVMParametersList().addProperty(MavenModuleMap.PATHS_FILE_PROPERTY, modulesPathsFile.getAbsolutePath());
|
||||
}
|
||||
catch (IOException e) {
|
||||
LOG.error(e);
|
||||
throw new ExecutionException("Failed to run maven configuration", e);
|
||||
}
|
||||
}
|
||||
|
||||
params.getVMParametersList().addProperty("classworlds.conf", confFile.getPath());
|
||||
|
||||
for (String path : getMavenClasspathEntries(mavenHome)) {
|
||||
params.getClassPath().add(path);
|
||||
}
|
||||
@@ -122,6 +153,112 @@ public class MavenExternalParameters {
|
||||
return params;
|
||||
}
|
||||
|
||||
private static File patchConfFile(File conf, String library) throws IOException {
|
||||
File tmpConf = File.createTempFile("idea-", "-mvn.conf");
|
||||
tmpConf.deleteOnExit();
|
||||
patchConfFile(conf, tmpConf, library);
|
||||
|
||||
return tmpConf;
|
||||
}
|
||||
|
||||
private static void patchConfFile(File originalConf, File dest, String library) throws IOException {
|
||||
Scanner sc = new Scanner(originalConf);
|
||||
|
||||
try {
|
||||
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(dest)));
|
||||
|
||||
try {
|
||||
boolean patched = false;
|
||||
|
||||
while (sc.hasNextLine()) {
|
||||
String line = sc.nextLine();
|
||||
|
||||
out.append(line);
|
||||
out.newLine();
|
||||
|
||||
if (!patched && "[plexus.core]".equals(line)) {
|
||||
out.append("load ").append(library);
|
||||
out.newLine();
|
||||
|
||||
patched = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
finally {
|
||||
sc.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static String getArtifactResolverJar(boolean isMaven3) throws IOException {
|
||||
Class marker = isMaven3 ? MavenArtifactResolvedM3RtMarker.class : MavenArtifactResolvedM2RtMarker.class;
|
||||
|
||||
File classDirOrJar = new File(PathUtil.getJarPathForClass(marker));
|
||||
|
||||
if (!classDirOrJar.isDirectory()) {
|
||||
return classDirOrJar.getAbsolutePath(); // it's a jar in IDEA installation.
|
||||
}
|
||||
|
||||
// it's a classes directory, we are in development mode.
|
||||
File tempFile = FileUtil.createTempFile("idea-", "-artifactResolver.jar");
|
||||
tempFile.deleteOnExit();
|
||||
|
||||
ZipOutputStream zipOutput = new ZipOutputStream(new FileOutputStream(tempFile));
|
||||
try {
|
||||
ZipUtil.addDirToZipRecursively(zipOutput, null, classDirOrJar, "", null, null);
|
||||
|
||||
if (isMaven3) {
|
||||
File m2Module = new File(PathUtil.getJarPathForClass(MavenModuleMap.class));
|
||||
|
||||
String commonClassesPath = MavenModuleMap.class.getPackage().getName().replace('.', '/');
|
||||
ZipUtil.addDirToZipRecursively(zipOutput, null, new File(m2Module, commonClassesPath), commonClassesPath, null, null);
|
||||
}
|
||||
} finally {
|
||||
zipOutput.close();
|
||||
}
|
||||
|
||||
return tempFile.getAbsolutePath();
|
||||
}
|
||||
|
||||
private static File dumpModulesPaths(@NotNull Project project) throws IOException {
|
||||
ApplicationManager.getApplication().assertReadAccessAllowed();
|
||||
|
||||
Properties res = new Properties();
|
||||
|
||||
MavenProjectsManager manager = MavenProjectsManager.getInstance(project);
|
||||
|
||||
for (MavenProject mavenProject : manager.getProjects()) {
|
||||
res.setProperty(mavenProject.getMavenId().getGroupId()
|
||||
+ ':' + mavenProject.getMavenId().getArtifactId()
|
||||
+ ":pom"
|
||||
+ ':' + mavenProject.getMavenId().getVersion(),
|
||||
mavenProject.getFile().getPath());
|
||||
|
||||
res.setProperty(mavenProject.getMavenId().getGroupId()
|
||||
+ ':' + mavenProject.getMavenId().getArtifactId()
|
||||
+ ':' + mavenProject.getPackaging()
|
||||
+ ':' + mavenProject.getMavenId().getVersion(),
|
||||
mavenProject.getOutputDirectory());
|
||||
}
|
||||
|
||||
File file = new File(PathManager.getSystemPath(), "Maven/idea-projects-state-" + project.getLocationHash() + ".properties");
|
||||
file.getParentFile().mkdirs();
|
||||
|
||||
OutputStream out = new BufferedOutputStream(new FileOutputStream(file));
|
||||
try {
|
||||
res.store(out, null);
|
||||
}
|
||||
finally {
|
||||
out.close();
|
||||
}
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Sdk getJdk(@Nullable Project project, MavenRunnerSettings runnerSettings, boolean isGlobalRunnerSettings) throws ExecutionException {
|
||||
String name = runnerSettings.getJreName();
|
||||
@@ -177,8 +314,6 @@ public class MavenExternalParameters {
|
||||
|
||||
parametersList.addParametersString(runnerSettings.getVmOptions());
|
||||
|
||||
parametersList.addProperty("classworlds.conf", MavenUtil.getMavenConfFile(new File(mavenHome)).getPath());
|
||||
|
||||
parametersList.addProperty("maven.home", mavenHome);
|
||||
}
|
||||
|
||||
@@ -310,8 +445,8 @@ public class MavenExternalParameters {
|
||||
if (coreSettings.isWorkOffline()) {
|
||||
cmdList.add("--offline");
|
||||
}
|
||||
String version = MavenUtil.getMavenVersion(mavenHome);
|
||||
boolean atLeastMaven3 = version != null && version.compareTo("3.0.0") >= 0;
|
||||
|
||||
boolean atLeastMaven3 = MavenUtil.isMaven3(mavenHome);
|
||||
|
||||
if (!atLeastMaven3) {
|
||||
addIfNotEmpty(cmdList, coreSettings.getPluginUpdatePolicy().getCommandLineOption());
|
||||
|
||||
+12
@@ -33,6 +33,8 @@ public class MavenRunnerParameters implements Cloneable {
|
||||
private Path myWorkingDirPath;
|
||||
private final List<String> myGoals = new ArrayList<String>();
|
||||
|
||||
private boolean myResolveToWorkspace;
|
||||
|
||||
private final Map<String, Boolean> myProfilesMap = new LinkedHashMap<String, Boolean>();
|
||||
|
||||
private final Collection<String> myEnabledProfilesForXmlSerializer = new TreeSet<String>();
|
||||
@@ -81,6 +83,7 @@ public class MavenRunnerParameters implements Cloneable {
|
||||
|
||||
public MavenRunnerParameters(MavenRunnerParameters that) {
|
||||
this(that.getWorkingDirPath(), that.isPomExecution, that.myGoals, that.myProfilesMap);
|
||||
myResolveToWorkspace = that.myResolveToWorkspace;
|
||||
}
|
||||
|
||||
public boolean isPomExecution() {
|
||||
@@ -180,6 +183,14 @@ public class MavenRunnerParameters implements Cloneable {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isResolveToWorkspace() {
|
||||
return myResolveToWorkspace;
|
||||
}
|
||||
|
||||
public void setResolveToWorkspace(boolean resolveToWorkspace) {
|
||||
myResolveToWorkspace = resolveToWorkspace;
|
||||
}
|
||||
|
||||
public MavenRunnerParameters clone() {
|
||||
return new MavenRunnerParameters(this);
|
||||
}
|
||||
@@ -191,6 +202,7 @@ public class MavenRunnerParameters implements Cloneable {
|
||||
final MavenRunnerParameters that = (MavenRunnerParameters)o;
|
||||
|
||||
if (isPomExecution != that.isPomExecution) return false;
|
||||
if (myResolveToWorkspace != that.myResolveToWorkspace) return false;
|
||||
if (!myGoals.equals(that.myGoals)) return false;
|
||||
if (myWorkingDirPath != null ? !myWorkingDirPath.equals(that.myWorkingDirPath) : that.myWorkingDirPath != null) return false;
|
||||
if (!myProfilesMap.equals(that.myProfilesMap)) return false;
|
||||
|
||||
+10
-2
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.jetbrains.idea.maven.execution.MavenRunnerParametersConfigurable">
|
||||
<grid id="27dc6" binding="panel" layout-manager="GridLayoutManager" row-count="4" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<grid id="27dc6" binding="panel" layout-manager="GridLayoutManager" row-count="5" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="500" height="400"/>
|
||||
@@ -20,7 +20,7 @@
|
||||
</component>
|
||||
<vspacer id="3a9c4">
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<component id="2a808" class="com.intellij.openapi.ui.LabeledComponent" binding="goalsComponent">
|
||||
@@ -70,6 +70,14 @@
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<component id="76fd8" class="javax.swing.JCheckBox" binding="myResolveToWorkspaceCheckBox">
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Resolve &Workspace artifacts"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
|
||||
+4
@@ -27,6 +27,7 @@ import com.intellij.openapi.ui.TextFieldWithBrowseButton;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.ui.EditorTextField;
|
||||
import com.intellij.ui.PanelWithAnchor;
|
||||
import com.intellij.ui.components.JBCheckBox;
|
||||
import com.intellij.ui.components.JBLabel;
|
||||
import com.intellij.util.TextFieldCompletionProvider;
|
||||
import com.intellij.util.execution.ParametersListUtil;
|
||||
@@ -50,6 +51,7 @@ public abstract class MavenRunnerParametersConfigurable implements Configurable,
|
||||
protected LabeledComponent<EditorTextField> goalsComponent;
|
||||
private LabeledComponent<EditorTextField> profilesComponent;
|
||||
private JBLabel myFakeLabel;
|
||||
private JCheckBox myResolveToWorkspaceCheckBox;
|
||||
private JComponent anchor;
|
||||
|
||||
public MavenRunnerParametersConfigurable(@NotNull final Project project) {
|
||||
@@ -126,6 +128,7 @@ public abstract class MavenRunnerParametersConfigurable implements Configurable,
|
||||
private void setData(final MavenRunnerParameters data) {
|
||||
data.setWorkingDirPath(workingDirComponent.getComponent().getText());
|
||||
data.setGoals(ParametersListUtil.parse(goalsComponent.getComponent().getText()));
|
||||
data.setResolveToWorkspace(myResolveToWorkspaceCheckBox.isSelected());
|
||||
|
||||
Map<String, Boolean> profilesMap = new LinkedHashMap<String, Boolean>();
|
||||
|
||||
@@ -146,6 +149,7 @@ public abstract class MavenRunnerParametersConfigurable implements Configurable,
|
||||
private void getData(final MavenRunnerParameters data) {
|
||||
workingDirComponent.getComponent().setText(data.getWorkingDirPath());
|
||||
goalsComponent.getComponent().setText(ParametersList.join(data.getGoals()));
|
||||
myResolveToWorkspaceCheckBox.setSelected(data.isResolveToWorkspace());
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Map.Entry<String, Boolean> entry : data.getProfilesMap().entrySet()) {
|
||||
|
||||
@@ -615,6 +615,11 @@ public class MavenUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean isMaven3(String mavenHome) {
|
||||
String version = getMavenVersion(mavenHome);
|
||||
return version != null && version.compareTo("3.0.0") >= 0;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static File resolveGlobalSettingsFile(@Nullable String overriddenMavenHome) {
|
||||
File directory = resolveMavenHomeDirectory(overriddenMavenHome);
|
||||
|
||||
Reference in New Issue
Block a user