mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-96219 External build: support all options of ant configuration for ant post/preprocessing tasks in artifacts
This commit is contained in:
+2
-2
@@ -1,6 +1,5 @@
|
||||
package org.jetbrains.jps.model.serialization;
|
||||
|
||||
import com.intellij.openapi.util.JDOMUtil;
|
||||
import com.intellij.testFramework.PlatformTestUtil;
|
||||
import org.jdom.Element;
|
||||
import org.jdom.JDOMException;
|
||||
@@ -34,7 +33,8 @@ public class JpsGlobalSerializationTest extends JpsSerializationTestCase {
|
||||
Element actual = new Element("component").setAttribute("name", "ProjectJdkTable");
|
||||
JpsSdkTableSerializer.saveSdks(myModel.getGlobal().getLibraryCollection(), actual);
|
||||
File jdkTableFile = new File(getTestDataFileAbsolutePath(OPTIONS_DIR), "jdk.table.xml");
|
||||
Element expected = JDomSerializationUtil.findComponent(JDOMUtil.loadDocument(jdkTableFile).getRootElement(), "ProjectJdkTable");
|
||||
JpsMacroExpander expander = new JpsMacroExpander(getPathVariables());
|
||||
Element expected = JDomSerializationUtil.findComponent(JpsLoaderBase.loadRootElement(jdkTableFile, expander), "ProjectJdkTable");
|
||||
PlatformTestUtil.assertElementsEqual(expected, actual);
|
||||
}
|
||||
|
||||
|
||||
+19
-3
@@ -1,15 +1,19 @@
|
||||
package org.jetbrains.jps.model.serialization;
|
||||
|
||||
import com.intellij.application.options.PathMacrosImpl;
|
||||
import com.intellij.openapi.application.ex.PathManagerEx;
|
||||
import com.intellij.openapi.util.io.FileUtilRt;
|
||||
import com.intellij.openapi.vfs.VfsUtilCore;
|
||||
import com.intellij.util.PathUtil;
|
||||
import com.intellij.util.SystemProperties;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.jps.model.JpsModelTestCase;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
@@ -27,7 +31,7 @@ public abstract class JpsSerializationTestCase extends JpsModelTestCase {
|
||||
myProjectHomePath = PathUtil.getParentPath(myProjectHomePath);
|
||||
}
|
||||
try {
|
||||
JpsProjectLoader.loadProject(myProject, Collections.<String, String>emptyMap(), path);
|
||||
JpsProjectLoader.loadProject(myProject, getPathVariables(), path);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
@@ -35,19 +39,31 @@ public abstract class JpsSerializationTestCase extends JpsModelTestCase {
|
||||
}
|
||||
|
||||
protected String getUrl(String relativePath) {
|
||||
return VfsUtilCore.pathToUrl(myProjectHomePath + "/" + relativePath);
|
||||
return VfsUtilCore.pathToUrl(getAbsolutePath(relativePath));
|
||||
}
|
||||
|
||||
protected String getAbsolutePath(String relativePath) {
|
||||
return myProjectHomePath + "/" + relativePath;
|
||||
}
|
||||
|
||||
protected void loadGlobalSettings(final String optionsDir) {
|
||||
try {
|
||||
String optionsPath = getTestDataFileAbsolutePath(optionsDir);
|
||||
JpsGlobalLoader.loadGlobalSettings(myModel.getGlobal(), Collections.<String, String>emptyMap(), optionsPath);
|
||||
Map<String,String> pathVariables = getPathVariables();
|
||||
JpsGlobalLoader.loadGlobalSettings(myModel.getGlobal(), pathVariables, optionsPath);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected Map<String, String> getPathVariables() {
|
||||
Map<String, String> variables = new HashMap<String, String>();
|
||||
variables.put(PathMacrosImpl.APPLICATION_HOME_MACRO_NAME, PathManagerEx.getHomePath(getClass()));
|
||||
variables.put(PathMacrosImpl.USER_HOME_MACRO_NAME, SystemProperties.getUserHome());
|
||||
return variables;
|
||||
}
|
||||
|
||||
protected String getTestDataFileAbsolutePath(String relativePath) {
|
||||
return PathManagerEx.findFileUnderProjectHome(relativePath, getClass()).getAbsolutePath();
|
||||
}
|
||||
|
||||
+6
-1
@@ -26,12 +26,14 @@ import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.rt.ant.execution.AntMain2;
|
||||
import com.intellij.util.SystemProperties;
|
||||
import com.intellij.util.execution.ParametersListUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jps.ant.model.JpsAntBuildFileOptions;
|
||||
import org.jetbrains.jps.ant.model.JpsAntExtensionService;
|
||||
import org.jetbrains.jps.ant.model.JpsAntInstallation;
|
||||
import org.jetbrains.jps.ant.model.artifacts.JpsAntArtifactExtension;
|
||||
import org.jetbrains.jps.ant.model.impl.JpsAntInstallationImpl;
|
||||
import org.jetbrains.jps.builders.artifacts.ArtifactBuildTaskProvider;
|
||||
import org.jetbrains.jps.incremental.BuildTask;
|
||||
import org.jetbrains.jps.incremental.CompileContext;
|
||||
@@ -114,7 +116,8 @@ public class AntArtifactBuildTaskProvider extends ArtifactBuildTaskProvider {
|
||||
}
|
||||
JpsSdk<?> jdk = jdkLibrary.getProperties();
|
||||
|
||||
JpsAntInstallation antInstallation = JpsAntExtensionService.getBundledAntHome(context.getProjectDescriptor().getModel().getGlobal());
|
||||
JpsAntInstallation antInstallation = JpsAntExtensionService.getAntInstallationForBuildFile(context.getProjectDescriptor().getModel(),
|
||||
myExtension.getFileUrl());
|
||||
if (antInstallation == null) {
|
||||
reportError(context, "Ant installation is not configured");
|
||||
throw new ProjectBuildException();
|
||||
@@ -127,7 +130,9 @@ public class AntArtifactBuildTaskProvider extends ArtifactBuildTaskProvider {
|
||||
classpath.add(file.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
classpath.addAll(options.getAdditionalClasspath());
|
||||
classpath.addAll(antInstallation.getClasspath());
|
||||
JpsAntInstallationImpl.addAllJarsFromDirectory(classpath, new File(SystemProperties.getUserHome(), ".ant/lib"));
|
||||
classpath.add(PathManager.getJarPathForClass(AntMain2.class));
|
||||
|
||||
List<String> vmParams = new ArrayList<String>();
|
||||
|
||||
@@ -15,6 +15,10 @@
|
||||
*/
|
||||
package org.jetbrains.jps.ant.model;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
@@ -24,4 +28,13 @@ public interface JpsAntBuildFileOptions {
|
||||
String getCustomJdkName();
|
||||
|
||||
String getAntCommandLineParameters();
|
||||
|
||||
void setAntCommandLineParameters(String antCommandLineParameters);
|
||||
|
||||
@Nullable
|
||||
String getAntInstallationName();
|
||||
|
||||
boolean isUseProjectDefaultAnt();
|
||||
|
||||
List<String> getAdditionalClasspath();
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.jetbrains.jps.ant.model;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jps.model.JpsElement;
|
||||
|
||||
/**
|
||||
@@ -24,4 +25,7 @@ import org.jetbrains.jps.model.JpsElement;
|
||||
public interface JpsAntConfiguration extends JpsElement {
|
||||
@NotNull
|
||||
JpsAntBuildFileOptions getOptions(@NotNull String buildFileUrl);
|
||||
|
||||
@Nullable
|
||||
String getProjectDefaultAntName();
|
||||
}
|
||||
|
||||
@@ -21,14 +21,18 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jps.ant.model.artifacts.JpsAntArtifactExtension;
|
||||
import org.jetbrains.jps.ant.model.impl.JpsAntBuildFileOptionsImpl;
|
||||
import org.jetbrains.jps.ant.model.impl.JpsAntConfigurationImpl;
|
||||
import org.jetbrains.jps.ant.model.impl.JpsAntInstallationImpl;
|
||||
import org.jetbrains.jps.ant.model.impl.artifacts.JpsAntArtifactExtensionImpl;
|
||||
import org.jetbrains.jps.model.JpsElementCollection;
|
||||
import org.jetbrains.jps.model.JpsGlobal;
|
||||
import org.jetbrains.jps.model.JpsModel;
|
||||
import org.jetbrains.jps.model.JpsProject;
|
||||
import org.jetbrains.jps.model.artifact.JpsArtifact;
|
||||
import org.jetbrains.jps.model.serialization.JpsGlobalLoader;
|
||||
import org.jetbrains.jps.model.serialization.PathMacroUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
@@ -46,9 +50,13 @@ public class JpsAntExtensionService {
|
||||
return artifact.getContainer().getChild(JpsAntArtifactExtensionImpl.POSTPROCESSING_ROLE);
|
||||
}
|
||||
|
||||
public static void addAntInstallation(JpsGlobal global, JpsAntInstallation antInstallation) {
|
||||
global.getContainer().getOrSetChild(JpsAntInstallationImpl.COLLECTION_ROLE).addChild(antInstallation);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JpsAntBuildFileOptions getOptions(@NotNull JpsProject project, @NotNull String buildFileUrl) {
|
||||
JpsAntConfiguration configuration = project.getContainer().getChild(JpsAntConfigurationImpl.ROLE);
|
||||
JpsAntConfiguration configuration = getAntConfiguration(project);
|
||||
if (configuration != null) {
|
||||
return configuration.getOptions(buildFileUrl);
|
||||
}
|
||||
@@ -56,7 +64,12 @@ public class JpsAntExtensionService {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static JpsAntInstallation getBundledAntHome(@NotNull JpsGlobal global) {
|
||||
private static JpsAntConfiguration getAntConfiguration(JpsProject project) {
|
||||
return project.getContainer().getChild(JpsAntConfigurationImpl.ROLE);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static JpsAntInstallation getBundledAntInstallation(@NotNull JpsGlobal global) {
|
||||
String appHome = JpsGlobalLoader.getPathVariable(global, PathMacroUtil.APPLICATION_HOME_DIR);
|
||||
if (appHome == null) {
|
||||
LOG.debug(PathMacroUtil.APPLICATION_HOME_DIR + " path variable not found, bundled Ant won't be configured");
|
||||
@@ -75,6 +88,41 @@ public class JpsAntExtensionService {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new JpsAntInstallation(antHome);
|
||||
String antLib = new File(antHome, "lib").getAbsolutePath();
|
||||
return new JpsAntInstallationImpl(antHome, "Bundled Ant", Collections.<String>emptyList(), Collections.singletonList(antLib));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static JpsAntInstallation getAntInstallationForBuildFile(@NotNull JpsModel model, @NotNull String buildFileUrl) {
|
||||
JpsAntBuildFileOptions options = getOptions(model.getProject(), buildFileUrl);
|
||||
String antInstallationName;
|
||||
if (options.isUseProjectDefaultAnt()) {
|
||||
JpsAntConfiguration antConfiguration = getAntConfiguration(model.getProject());
|
||||
antInstallationName = antConfiguration != null ? antConfiguration.getProjectDefaultAntName() : null;
|
||||
}
|
||||
else {
|
||||
antInstallationName = options.getAntInstallationName();
|
||||
}
|
||||
|
||||
if (antInstallationName == null) return getBundledAntInstallation(model.getGlobal());
|
||||
|
||||
return findAntInstallation(model, antInstallationName);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static JpsAntInstallation findAntInstallation(@NotNull JpsModel model, @NotNull String antInstallationName) {
|
||||
JpsElementCollection<JpsAntInstallation> antInstallations = model.getGlobal().getContainer().getChild(JpsAntInstallationImpl.COLLECTION_ROLE);
|
||||
if (antInstallations != null) {
|
||||
for (JpsAntInstallation installation : antInstallations.getElements()) {
|
||||
if (antInstallationName.equals(installation.getName())) {
|
||||
return installation;
|
||||
}
|
||||
}
|
||||
LOG.debug("Ant installation '" + antInstallationName + "' not found");
|
||||
}
|
||||
else {
|
||||
LOG.debug("Ant installations weren't loaded");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,37 +15,18 @@
|
||||
*/
|
||||
package org.jetbrains.jps.ant.model;
|
||||
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import org.jetbrains.jps.model.JpsElement;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class JpsAntInstallation {
|
||||
private File myAntHome;
|
||||
public interface JpsAntInstallation extends JpsElement {
|
||||
File getAntHome();
|
||||
|
||||
public JpsAntInstallation(File antHome) {
|
||||
myAntHome = antHome;
|
||||
}
|
||||
List<String> getClasspath();
|
||||
|
||||
public File getAntHome() {
|
||||
return myAntHome;
|
||||
}
|
||||
|
||||
public List<String> getClasspath() {
|
||||
File lib = new File(myAntHome, "lib");
|
||||
List<String> result = new ArrayList<String>();
|
||||
File[] files = lib.listFiles();
|
||||
if (files != null) {
|
||||
for (File file : files) {
|
||||
if (StringUtil.endsWithIgnoreCase(file.getName(), ".jar")) {
|
||||
result.add(file.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
String getName();
|
||||
}
|
||||
|
||||
+39
@@ -17,6 +17,9 @@ package org.jetbrains.jps.ant.model.impl;
|
||||
|
||||
import org.jetbrains.jps.ant.model.JpsAntBuildFileOptions;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
@@ -25,15 +28,41 @@ public class JpsAntBuildFileOptionsImpl implements JpsAntBuildFileOptions {
|
||||
private String myAntCommandLineParameters = "";
|
||||
private int myMaxHeapSize = 128;
|
||||
private String myCustomJdkName = "";
|
||||
private boolean myUseProjectDefaultAnt = true;
|
||||
private String myAntInstallationName;
|
||||
private List<String> myClasspath = new ArrayList<String>();
|
||||
private List<String> myJarDirectories = new ArrayList<String>();
|
||||
|
||||
public void setMaxStackSize(int maxStackSize) {
|
||||
myMaxStackSize = maxStackSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAntCommandLineParameters(String antCommandLineParameters) {
|
||||
myAntCommandLineParameters = antCommandLineParameters;
|
||||
}
|
||||
|
||||
public void setUseProjectDefaultAnt(boolean useProjectDefaultAnt) {
|
||||
myUseProjectDefaultAnt = useProjectDefaultAnt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAntInstallationName() {
|
||||
return myAntInstallationName;
|
||||
}
|
||||
|
||||
public void setAntInstallationName(String antInstallationName) {
|
||||
myAntInstallationName = antInstallationName;
|
||||
}
|
||||
|
||||
public void addJarPath(String path) {
|
||||
myClasspath.add(path);
|
||||
}
|
||||
|
||||
public void addJarDirectory(String directoryPath) {
|
||||
myJarDirectories.add(directoryPath);
|
||||
}
|
||||
|
||||
public void setMaxHeapSize(int maxHeapSize) {
|
||||
myMaxHeapSize = maxHeapSize;
|
||||
}
|
||||
@@ -61,4 +90,14 @@ public class JpsAntBuildFileOptionsImpl implements JpsAntBuildFileOptions {
|
||||
public String getAntCommandLineParameters() {
|
||||
return myAntCommandLineParameters;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseProjectDefaultAnt() {
|
||||
return myUseProjectDefaultAnt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getAdditionalClasspath() {
|
||||
return JpsAntInstallationImpl.getClasspath(myClasspath, myJarDirectories);
|
||||
}
|
||||
}
|
||||
|
||||
+11
-2
@@ -17,6 +17,7 @@ package org.jetbrains.jps.ant.model.impl;
|
||||
|
||||
import com.intellij.util.containers.hash.HashMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jps.ant.model.JpsAntBuildFileOptions;
|
||||
import org.jetbrains.jps.ant.model.JpsAntConfiguration;
|
||||
import org.jetbrains.jps.model.JpsElementChildRole;
|
||||
@@ -30,16 +31,24 @@ import java.util.Map;
|
||||
*/
|
||||
public class JpsAntConfigurationImpl extends JpsElementBase<JpsAntConfigurationImpl> implements JpsAntConfiguration {
|
||||
public static final JpsElementChildRole<JpsAntConfiguration> ROLE = JpsElementChildRoleBase.create("ant configuration");
|
||||
private final String myProjectDefaultAntName;
|
||||
private Map<String, JpsAntBuildFileOptions> myOptionsMap = new HashMap<String, JpsAntBuildFileOptions>();
|
||||
|
||||
public JpsAntConfigurationImpl(Map<String, JpsAntBuildFileOptions> options) {
|
||||
public JpsAntConfigurationImpl(Map<String, JpsAntBuildFileOptions> options, String projectDefaultAntName) {
|
||||
myProjectDefaultAntName = projectDefaultAntName;
|
||||
myOptionsMap.putAll(options);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JpsAntConfigurationImpl createCopy() {
|
||||
return new JpsAntConfigurationImpl(myOptionsMap);
|
||||
return new JpsAntConfigurationImpl(myOptionsMap, myProjectDefaultAntName);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String getProjectDefaultAntName() {
|
||||
return myProjectDefaultAntName;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright 2000-2012 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.jps.ant.model.impl;
|
||||
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jps.ant.model.JpsAntInstallation;
|
||||
import org.jetbrains.jps.model.ex.JpsElementBase;
|
||||
import org.jetbrains.jps.model.ex.JpsElementChildRoleBase;
|
||||
import org.jetbrains.jps.model.ex.JpsElementCollectionRole;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class JpsAntInstallationImpl extends JpsElementBase<JpsAntInstallationImpl> implements JpsAntInstallation {
|
||||
private final File myAntHome;
|
||||
private final String myName;
|
||||
private final List<String> myClasspath;
|
||||
private final List<String> myJarDirectories;
|
||||
public static final JpsElementChildRoleBase<JpsAntInstallation> ROLE = JpsElementChildRoleBase.create("ant installation");
|
||||
public static final JpsElementCollectionRole<JpsAntInstallation> COLLECTION_ROLE = JpsElementCollectionRole.create(ROLE);
|
||||
|
||||
public JpsAntInstallationImpl(File antHome, String name, final List<String> classpath, List<String> jarDirectories) {
|
||||
myAntHome = antHome;
|
||||
myName = name;
|
||||
myClasspath = classpath;
|
||||
myJarDirectories = jarDirectories;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JpsAntInstallationImpl createCopy() {
|
||||
return new JpsAntInstallationImpl(myAntHome, myName, myClasspath, myJarDirectories);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return myName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyChanges(@NotNull JpsAntInstallationImpl modified) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getAntHome() {
|
||||
return myAntHome;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getClasspath() {
|
||||
return getClasspath(myClasspath, myJarDirectories);
|
||||
}
|
||||
|
||||
public static List<String> getClasspath(final List<String> classpath, final List<String> jarDirectories) {
|
||||
List<String> result = new ArrayList<String>(classpath);
|
||||
for (String directory : jarDirectories) {
|
||||
addAllJarsFromDirectory(result, new File(directory));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void addAllJarsFromDirectory(List<String> classpath, final File dir) {
|
||||
File[] files = dir.listFiles();
|
||||
if (files != null) {
|
||||
for (File file : files) {
|
||||
if (StringUtil.endsWithIgnoreCase(file.getName(), ".jar")) {
|
||||
classpath.add(file.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+79
-11
@@ -24,6 +24,8 @@ import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jps.ant.model.JpsAntBuildFileOptions;
|
||||
import org.jetbrains.jps.ant.model.JpsAntConfiguration;
|
||||
import org.jetbrains.jps.ant.model.JpsAntExtensionService;
|
||||
import org.jetbrains.jps.ant.model.artifacts.JpsAntArtifactExtension;
|
||||
import org.jetbrains.jps.ant.model.impl.artifacts.AntArtifactExtensionProperties;
|
||||
import org.jetbrains.jps.ant.model.impl.artifacts.JpsAntArtifactExtensionImpl;
|
||||
@@ -34,11 +36,10 @@ import org.jetbrains.jps.model.serialization.JpsGlobalExtensionSerializer;
|
||||
import org.jetbrains.jps.model.serialization.JpsModelSerializerExtension;
|
||||
import org.jetbrains.jps.model.serialization.JpsProjectExtensionSerializer;
|
||||
import org.jetbrains.jps.model.serialization.artifact.JpsArtifactExtensionSerializer;
|
||||
import org.jetbrains.jps.util.JpsPathUtil;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
@@ -53,7 +54,7 @@ public class JpsAntModelSerializerExtension extends JpsModelSerializerExtension
|
||||
@NotNull
|
||||
@Override
|
||||
public List<? extends JpsProjectExtensionSerializer> getProjectExtensionSerializers() {
|
||||
return Collections.singletonList(new JpsProjectAntConfigurationSerializer());
|
||||
return Arrays.asList(new JpsProjectAntConfigurationSerializer(), new JpsWorkspaceAntConfigurationSerializer());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -80,6 +81,12 @@ public class JpsAntModelSerializerExtension extends JpsModelSerializerExtension
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static String getValueAttribute(Element buildFileTag, final String childName) {
|
||||
Element child = buildFileTag.getChild(childName);
|
||||
return child != null ? child.getAttributeValue("value") : null;
|
||||
}
|
||||
|
||||
private static class JpsGlobalAntConfigurationSerializer extends JpsGlobalExtensionSerializer {
|
||||
protected JpsGlobalAntConfigurationSerializer() {
|
||||
super("other.xml", "GlobalAntConfiguration");
|
||||
@@ -87,13 +94,32 @@ public class JpsAntModelSerializerExtension extends JpsModelSerializerExtension
|
||||
|
||||
@Override
|
||||
public void loadExtension(@NotNull JpsGlobal global, @NotNull Element componentTag) {
|
||||
}
|
||||
for (Element antTag : JDOMUtil.getChildren(componentTag.getChild("registeredAnts"), "ant")) {
|
||||
String name = getValueAttribute(antTag, "name");
|
||||
String homeDir = getValueAttribute(antTag, "homeDir");
|
||||
List<String> classpath = new ArrayList<String>();
|
||||
List<String> jarDirectories = new ArrayList<String>();
|
||||
for (Element classpathItemTag : JDOMUtil.getChildren(antTag.getChild("classpath"), "classpathItem")) {
|
||||
String fileUrl = classpathItemTag.getAttributeValue("path");
|
||||
String dirUrl = classpathItemTag.getAttributeValue("dir");
|
||||
if (fileUrl != null) {
|
||||
classpath.add(JpsPathUtil.urlToPath(fileUrl));
|
||||
}
|
||||
else if (dirUrl != null) {
|
||||
jarDirectories.add(JpsPathUtil.urlToPath(dirUrl));
|
||||
}
|
||||
}
|
||||
|
||||
if (name != null && homeDir != null) {
|
||||
JpsAntExtensionService.addAntInstallation(global, new JpsAntInstallationImpl(new File(homeDir), name, classpath, jarDirectories));
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void saveExtension(@NotNull JpsGlobal global, @NotNull Element componentTag) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
private static class JpsProjectAntConfigurationSerializer extends JpsProjectExtensionSerializer {
|
||||
private JpsProjectAntConfigurationSerializer() {
|
||||
super("ant.xml", "AntConfiguration");
|
||||
@@ -108,14 +134,56 @@ public class JpsAntModelSerializerExtension extends JpsModelSerializerExtension
|
||||
options.setMaxHeapSize(StringUtil.parseInt(getValueAttribute(buildFileTag, "maximumHeapSize"), 128));
|
||||
options.setMaxStackSize(StringUtil.parseInt(getValueAttribute(buildFileTag, "maximumStackSize"), 2));
|
||||
options.setCustomJdkName(getValueAttribute(buildFileTag, "customJdkName"));
|
||||
Element antReference = buildFileTag.getChild("antReference");
|
||||
if (antReference != null) {
|
||||
options.setUseProjectDefaultAnt(Boolean.parseBoolean(antReference.getAttributeValue("projectDefault")));
|
||||
options.setAntInstallationName(antReference.getAttributeValue("name"));
|
||||
}
|
||||
for (Element classpathEntry : JDOMUtil.getChildren(buildFileTag.getChild("additionalClassPath"), "entry")) {
|
||||
String fileUrl = classpathEntry.getAttributeValue("path");
|
||||
String dirUrl = classpathEntry.getAttributeValue("dir");
|
||||
if (fileUrl != null) {
|
||||
options.addJarPath(JpsPathUtil.urlToPath(fileUrl));
|
||||
}
|
||||
else if (dirUrl != null) {
|
||||
options.addJarDirectory(JpsPathUtil.urlToPath(dirUrl));
|
||||
}
|
||||
}
|
||||
optionsMap.put(url, options);
|
||||
}
|
||||
project.getContainer().setChild(JpsAntConfigurationImpl.ROLE, new JpsAntConfigurationImpl(optionsMap));
|
||||
Element defaultAnt = componentTag.getChild("defaultAnt");
|
||||
String projectDefaultAntName;
|
||||
if (defaultAnt != null) {
|
||||
projectDefaultAntName = defaultAnt.getAttributeValue("name");
|
||||
}
|
||||
else {
|
||||
projectDefaultAntName = null;
|
||||
}
|
||||
project.getContainer().setChild(JpsAntConfigurationImpl.ROLE, new JpsAntConfigurationImpl(optionsMap, projectDefaultAntName));
|
||||
}
|
||||
|
||||
private static String getValueAttribute(Element buildFileTag, final String childName) {
|
||||
Element child = buildFileTag.getChild(childName);
|
||||
return child != null ? child.getAttributeValue("value") : "";
|
||||
@Override
|
||||
public void saveExtension(@NotNull JpsProject project, @NotNull Element componentTag) {
|
||||
}
|
||||
}
|
||||
|
||||
private static class JpsWorkspaceAntConfigurationSerializer extends JpsProjectExtensionSerializer {
|
||||
private JpsWorkspaceAntConfigurationSerializer() {
|
||||
super(WORKSPACE_FILE, "antWorkspaceConfiguration");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadExtension(@NotNull JpsProject project, @NotNull Element componentTag) {
|
||||
for (Element buildFileTag : JDOMUtil.getChildren(componentTag, "buildFile")) {
|
||||
String commandLine = getValueAttribute(buildFileTag, "antCommandLine");
|
||||
String url = buildFileTag.getAttributeValue("url");
|
||||
if (!StringUtil.isEmpty(commandLine)) {
|
||||
JpsAntConfiguration configuration = project.getContainer().getChild(JpsAntConfigurationImpl.ROLE);
|
||||
if (configuration != null) {
|
||||
configuration.getOptions(url).setAntCommandLineParameters(commandLine);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+4
-1
@@ -3,7 +3,10 @@
|
||||
<component name="AntConfiguration">
|
||||
<defaultAnt bundledAnt="true" />
|
||||
<buildFile url="file://$PROJECT_DIR$/build.xml">
|
||||
<additionalClassPath />
|
||||
<additionalClassPath>
|
||||
<entry path="file://$PROJECT_DIR$/lib/jdom.jar" />
|
||||
<entry dir="file://$PROJECT_DIR$/ant-lib" />
|
||||
</additionalClassPath>
|
||||
<antReference projectDefault="true" />
|
||||
<customJdkName value="" />
|
||||
<maximumHeapSize value="128" />
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="antWorkspaceConfiguration">
|
||||
<option name="IS_AUTOSCROLL_TO_SOURCE" value="false" />
|
||||
<option name="FILTER_TARGETS" value="false" />
|
||||
<buildFile url="file://$PROJECT_DIR$/build.xml">
|
||||
<antCommandLine value="-J-Dmy.ant.prop=123" />
|
||||
<runInBackground value="true" />
|
||||
<targetFilters>
|
||||
<filter targetName="show-message" isVisible="false" />
|
||||
<filter targetName="create-file" isVisible="false" />
|
||||
</targetFilters>
|
||||
<treeView value="true" />
|
||||
<verbose value="true" />
|
||||
<viewClosedWhenNoErrors value="false" />
|
||||
<expanded value="true" />
|
||||
</buildFile>
|
||||
<buildFile url="file://$PROJECT_DIR$/empty.xml">
|
||||
<antCommandLine value="" />
|
||||
<runInBackground value="true" />
|
||||
<targetFilters />
|
||||
<treeView value="true" />
|
||||
<verbose value="true" />
|
||||
<viewClosedWhenNoErrors value="false" />
|
||||
<expanded value="true" />
|
||||
</buildFile>
|
||||
</component>
|
||||
</project>
|
||||
|
||||
@@ -19,6 +19,16 @@
|
||||
<name value="Apache Ant version 1.8.2" />
|
||||
<version value="1.8.2" />
|
||||
</ant>
|
||||
<ant>
|
||||
<classpath>
|
||||
<classpathItem dir="file://$APPLICATION_HOME_DIR$/lib/ant/lib" />
|
||||
<classpathItem path="file://$APPLICATION_HOME_DIR$/lib/asm.jar" />
|
||||
<classpathItem dir="file://$APPLICATION_HOME_DIR$/lib/dev" />
|
||||
</classpath>
|
||||
<homeDir value="$APPLICATION_HOME_DIR$/lib/ant" />
|
||||
<name value="Patched Ant" />
|
||||
<version value="1.8.2" />
|
||||
</ant>
|
||||
</registeredAnts>
|
||||
</component>
|
||||
</application>
|
||||
|
||||
@@ -16,21 +16,29 @@
|
||||
package org.jetbrains.jps.ant;
|
||||
|
||||
import com.intellij.lang.ant.config.impl.BuildFileProperty;
|
||||
import com.intellij.openapi.application.ex.PathManagerEx;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.util.SystemProperties;
|
||||
import gnu.trove.THashSet;
|
||||
import org.jetbrains.jps.ant.model.JpsAntBuildFileOptions;
|
||||
import org.jetbrains.jps.ant.model.JpsAntExtensionService;
|
||||
import org.jetbrains.jps.ant.model.JpsAntInstallation;
|
||||
import org.jetbrains.jps.ant.model.artifacts.JpsAntArtifactExtension;
|
||||
import org.jetbrains.jps.ant.model.impl.artifacts.JpsAntArtifactExtensionImpl;
|
||||
import org.jetbrains.jps.model.artifact.JpsArtifact;
|
||||
import org.jetbrains.jps.model.artifact.JpsArtifactService;
|
||||
import org.jetbrains.jps.model.serialization.JpsSerializationTestCase;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class JpsAntSerializationTest extends JpsSerializationTestCase {
|
||||
public static final String PROJECT_PATH = "plugins/ant/jps-plugin/testData/ant-project";
|
||||
public static final String OPTIONS_PATH = "plugins/ant/jps-plugin/testData/config/options";
|
||||
|
||||
public void testLoadArtifactProperties() {
|
||||
loadProject(PROJECT_PATH);
|
||||
@@ -65,14 +73,53 @@ public class JpsAntSerializationTest extends JpsSerializationTestCase {
|
||||
assertNull(JpsAntExtensionService.getPreprocessingExtension(jar));
|
||||
}
|
||||
|
||||
public void testLoadAntInstallations() {
|
||||
loadGlobalSettings(OPTIONS_PATH);
|
||||
JpsAntInstallation installation = JpsAntExtensionService.findAntInstallation(myModel, "Apache Ant version 1.8.2");
|
||||
assertNotNull(installation);
|
||||
assertEquals(FileUtil.toSystemIndependentName(installation.getAntHome().getAbsolutePath()),
|
||||
FileUtil.toSystemIndependentName(new File(SystemProperties.getUserHome(), "applications/apache-ant-1.8.2").getAbsolutePath()));
|
||||
|
||||
JpsAntInstallation installation2 = JpsAntExtensionService.findAntInstallation(myModel, "Patched Ant");
|
||||
assertNotNull(installation2);
|
||||
assertContainsElements(toFiles(installation2.getClasspath()),
|
||||
PathManagerEx.findFileUnderCommunityHome("lib/ant/lib/ant.jar"),
|
||||
PathManagerEx.findFileUnderCommunityHome("lib/asm.jar"),
|
||||
PathManagerEx.findFileUnderCommunityHome("lib/dev/easymock.jar"));
|
||||
}
|
||||
|
||||
public void testLoadAntConfiguration() {
|
||||
loadProject(PROJECT_PATH);
|
||||
JpsAntBuildFileOptions options = JpsAntExtensionService.getOptions(myProject, getUrl("build.xml"));
|
||||
loadGlobalSettings(OPTIONS_PATH);
|
||||
String buildXmlUrl = getUrl("build.xml");
|
||||
JpsAntBuildFileOptions options = JpsAntExtensionService.getOptions(myProject, buildXmlUrl);
|
||||
assertEquals(128, options.getMaxHeapSize());
|
||||
assertEquals("-J-Dmy.ant.prop=123", options.getAntCommandLineParameters());
|
||||
assertContainsElements(toFiles(options.getAdditionalClasspath()),
|
||||
new File(getAbsolutePath("lib/jdom.jar")),
|
||||
new File(getAbsolutePath("ant-lib/a.jar")));
|
||||
|
||||
JpsAntBuildFileOptions options2 = JpsAntExtensionService.getOptions(myProject, getUrl("empty.xml"));
|
||||
String emptyFileUrl = getUrl("empty.xml");
|
||||
JpsAntBuildFileOptions options2 = JpsAntExtensionService.getOptions(myProject, emptyFileUrl);
|
||||
assertEquals(256, options2.getMaxHeapSize());
|
||||
assertEquals(10, options2.getMaxStackSize());
|
||||
assertEquals("1.6", options2.getCustomJdkName());
|
||||
|
||||
JpsAntInstallation bundled = JpsAntExtensionService.getAntInstallationForBuildFile(myModel, buildXmlUrl);
|
||||
assertNotNull(bundled);
|
||||
assertEquals("Bundled Ant", bundled.getName());
|
||||
|
||||
JpsAntInstallation installation = JpsAntExtensionService.getAntInstallationForBuildFile(myModel, emptyFileUrl);
|
||||
assertNotNull(installation);
|
||||
assertEquals("Apache Ant version 1.8.2", installation.getName());
|
||||
|
||||
}
|
||||
|
||||
private static Set<File> toFiles(List<String> classpath) {
|
||||
Set<File> result = new THashSet<File>(FileUtil.FILE_HASHING_STRATEGY);
|
||||
for (String path : classpath) {
|
||||
result.add(new File(path));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user