Search in sources :

Example 36 with JpsArtifact

use of org.jetbrains.jps.model.artifact.JpsArtifact in project intellij-community by JetBrains.

the class RebuildArtifactOnConfigurationChangeTest method testAddRootChangingRootIndices.

public void testAddRootChangingRootIndices() {
    String file1 = createFile("d1/a/b/1.txt");
    String file2 = createFile("d2/x/y/2.txt");
    JpsArtifact a = addArtifact(root().fileCopy(file1).fileCopy(file2));
    buildAll();
    assertOutput(a, fs().file("1.txt").file("2.txt"));
    JpsCompositePackagingElement root = a.getRootElement();
    assertEquals(2, root.getChildren().size());
    JpsPackagingElement last = root.getChildren().get(1);
    root.removeChild(last);
    String file3 = createFile("d3/1/2/3.txt");
    root.addChild(JpsPackagingElementFactory.getInstance().createFileCopy(file3, null));
    root.addChild(last);
    buildAll();
    assertOutput(a, fs().file("1.txt").file("2.txt").file("3.txt"));
}
Also used : JpsPackagingElement(org.jetbrains.jps.model.artifact.elements.JpsPackagingElement) JpsArtifact(org.jetbrains.jps.model.artifact.JpsArtifact) JpsCompositePackagingElement(org.jetbrains.jps.model.artifact.elements.JpsCompositePackagingElement)

Example 37 with JpsArtifact

use of org.jetbrains.jps.model.artifact.JpsArtifact in project android by JetBrains.

the class AndroidSourceGeneratingBuilder method checkUnambiguousAndRecursiveArtifacts.

private static boolean checkUnambiguousAndRecursiveArtifacts(CompileContext context, List<JpsArtifact> artifacts) {
    boolean success = true;
    for (JpsArtifact artifact : artifacts) {
        if (artifact.getArtifactType() instanceof AndroidApplicationArtifactType) {
            final List<JpsAndroidModuleExtension> facets = AndroidJpsUtil.getAllPackagedFacets(artifact);
            if (facets.size() > 1) {
                context.processMessage(new CompilerMessage(ANDROID_VALIDATOR, BuildMessage.Kind.ERROR, "Cannot build artifact '" + artifact.getName() + "' because it contains more than one Android package"));
                success = false;
                continue;
            }
            final String artifactOutputPath = artifact.getOutputFilePath();
            if (artifactOutputPath != null && facets.size() > 0) {
                final JpsAndroidModuleExtension facet = facets.get(0);
                final String apkPath = AndroidFinalPackageElementBuilder.getApkPath(facet);
                if (FileUtil.pathsEqual(apkPath, artifactOutputPath)) {
                    context.processMessage(new CompilerMessage(ANDROID_VALIDATOR, BuildMessage.Kind.ERROR, "Incorrect output path for artifact '" + artifact.getName() + "': " + FileUtil.toSystemDependentName(apkPath)));
                    success = false;
                }
            }
        }
    }
    return success;
}
Also used : CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) JpsAndroidModuleExtension(org.jetbrains.jps.android.model.JpsAndroidModuleExtension) JpsArtifact(org.jetbrains.jps.model.artifact.JpsArtifact) AndroidApplicationArtifactType(org.jetbrains.jps.android.model.AndroidApplicationArtifactType)

Example 38 with JpsArtifact

use of org.jetbrains.jps.model.artifact.JpsArtifact in project android by JetBrains.

the class AndroidSourceGeneratingBuilder method checkArtifacts.

private static boolean checkArtifacts(@NotNull CompileContext context) {
    final List<JpsArtifact> artifacts = AndroidJpsUtil.getAndroidArtifactsToBuild(context);
    if (!checkUnambiguousAndRecursiveArtifacts(context, artifacts)) {
        return false;
    }
    final Set<JpsArtifact> debugArtifacts = new HashSet<JpsArtifact>();
    final Set<JpsArtifact> releaseArtifacts = new HashSet<JpsArtifact>();
    final Map<String, List<JpsArtifact>> moduleName2Artifact = new HashMap<String, List<JpsArtifact>>();
    for (JpsArtifact artifact : artifacts) {
        final JpsElement properties = artifact.getProperties();
        if (!(properties instanceof JpsAndroidApplicationArtifactProperties)) {
            continue;
        }
        final AndroidArtifactSigningMode mode = ((JpsAndroidApplicationArtifactProperties) properties).getSigningMode();
        if (mode == AndroidArtifactSigningMode.DEBUG || mode == AndroidArtifactSigningMode.DEBUG_WITH_CUSTOM_CERTIFICATE) {
            debugArtifacts.add(artifact);
        } else {
            releaseArtifacts.add(artifact);
        }
        final JpsAndroidModuleExtension facet = AndroidJpsUtil.getPackagedFacet(artifact);
        if (facet != null) {
            final String moduleName = facet.getModule().getName();
            List<JpsArtifact> list = moduleName2Artifact.get(moduleName);
            if (list == null) {
                list = new ArrayList<JpsArtifact>();
                moduleName2Artifact.put(moduleName, list);
            }
            list.add(artifact);
        }
    }
    boolean success = true;
    if (debugArtifacts.size() > 0 && releaseArtifacts.size() > 0) {
        final String message = "Cannot build debug and release Android artifacts in the same session\n" + "Debug artifacts: " + artifactsToString(debugArtifacts) + "\n" + "Release artifacts: " + artifactsToString(releaseArtifacts);
        context.processMessage(new CompilerMessage(ANDROID_VALIDATOR, BuildMessage.Kind.ERROR, message));
        success = false;
    }
    if (releaseArtifacts.size() > 0 && AndroidJpsUtil.getRunConfigurationTypeId(context) != null) {
        final String message = "Cannot build release Android artifacts in the 'build before run' session\n" + "Release artifacts: " + artifactsToString(releaseArtifacts);
        context.processMessage(new CompilerMessage(ANDROID_VALIDATOR, BuildMessage.Kind.ERROR, message));
        success = false;
    }
    for (Map.Entry<String, List<JpsArtifact>> entry : moduleName2Artifact.entrySet()) {
        final List<JpsArtifact> list = entry.getValue();
        final String moduleName = entry.getKey();
        if (list.size() > 1) {
            final JpsArtifact firstArtifact = list.get(0);
            final Object[] firstArtifactProGuardOptions = getProGuardOptions(firstArtifact);
            for (int i = 1; i < list.size(); i++) {
                final JpsArtifact artifact = list.get(i);
                if (!Arrays.equals(getProGuardOptions(artifact), firstArtifactProGuardOptions)) {
                    context.processMessage(new CompilerMessage(ANDROID_VALIDATOR, BuildMessage.Kind.ERROR, "Artifacts related to the same module '" + moduleName + "' have different ProGuard options: " + firstArtifact.getName() + ", " + artifact.getName()));
                    success = false;
                    break;
                }
            }
        }
    }
    return success;
}
Also used : JpsElement(org.jetbrains.jps.model.JpsElement) CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) HashMap(com.intellij.util.containers.HashMap) TObjectLongHashMap(gnu.trove.TObjectLongHashMap) JpsArtifact(org.jetbrains.jps.model.artifact.JpsArtifact) JpsAndroidApplicationArtifactProperties(org.jetbrains.jps.android.model.JpsAndroidApplicationArtifactProperties) JpsAndroidModuleExtension(org.jetbrains.jps.android.model.JpsAndroidModuleExtension) AndroidArtifactSigningMode(org.jetbrains.android.compiler.artifact.AndroidArtifactSigningMode) HashMap(com.intellij.util.containers.HashMap) TObjectLongHashMap(gnu.trove.TObjectLongHashMap) HashSet(com.intellij.util.containers.HashSet) THashSet(gnu.trove.THashSet)

Example 39 with JpsArtifact

use of org.jetbrains.jps.model.artifact.JpsArtifact in project intellij-community by JetBrains.

the class ArtifactBasedBuildTargetType method computeAllTargets.

@NotNull
@Override
public List<T> computeAllTargets(@NotNull JpsModel model) {
    Collection<JpsArtifact> artifacts = JpsBuilderArtifactService.getInstance().getArtifacts(model, true);
    List<T> targets = new ArrayList<>(artifacts.size());
    for (JpsArtifact artifact : artifacts) {
        if (!StringUtil.isEmpty(artifact.getOutputPath())) {
            targets.add(createArtifactBasedTarget(artifact));
        }
    }
    return targets;
}
Also used : JpsArtifact(org.jetbrains.jps.model.artifact.JpsArtifact) NotNull(org.jetbrains.annotations.NotNull)

Example 40 with JpsArtifact

use of org.jetbrains.jps.model.artifact.JpsArtifact in project intellij-community by JetBrains.

the class ArtifactBuildTarget method computeDependencies.

@Override
public Collection<BuildTarget<?>> computeDependencies(BuildTargetRegistry targetRegistry, final TargetOutputIndex outputIndex) {
    final LinkedHashSet<BuildTarget<?>> dependencies = new LinkedHashSet<>();
    final JpsArtifact artifact = getArtifact();
    JpsArtifactUtil.processPackagingElements(artifact.getRootElement(), element -> {
        if (element instanceof JpsArtifactOutputPackagingElement) {
            JpsArtifact included = ((JpsArtifactOutputPackagingElement) element).getArtifactReference().resolve();
            if (included != null && !included.equals(artifact)) {
                if (!StringUtil.isEmpty(included.getOutputPath())) {
                    dependencies.add(new ArtifactBuildTarget(included));
                    return false;
                }
            }
        }
        dependencies.addAll(LayoutElementBuildersRegistry.getInstance().getDependencies(element, outputIndex));
        return true;
    });
    if (!dependencies.isEmpty()) {
        final List<BuildTarget<?>> additional = new SmartList<>();
        for (BuildTarget<?> dependency : dependencies) {
            if (dependency instanceof ModuleBasedTarget<?>) {
                final ModuleBasedTarget target = (ModuleBasedTarget) dependency;
                additional.addAll(targetRegistry.getModuleBasedTargets(target.getModule(), target.isTests() ? BuildTargetRegistry.ModuleTargetSelector.TEST : BuildTargetRegistry.ModuleTargetSelector.PRODUCTION));
            }
        }
        dependencies.addAll(additional);
    }
    return dependencies;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) JpsArtifact(org.jetbrains.jps.model.artifact.JpsArtifact) SmartList(com.intellij.util.SmartList) JpsArtifactOutputPackagingElement(org.jetbrains.jps.model.artifact.elements.JpsArtifactOutputPackagingElement)

Aggregations

JpsArtifact (org.jetbrains.jps.model.artifact.JpsArtifact)85 File (java.io.File)10 JpsModule (org.jetbrains.jps.model.module.JpsModule)10 JarFile (java.util.jar.JarFile)4 ZipFile (java.util.zip.ZipFile)4 IOException (java.io.IOException)3 NotNull (org.jetbrains.annotations.NotNull)3 CompilerMessage (org.jetbrains.jps.incremental.messages.CompilerMessage)3 JpsCompositePackagingElement (org.jetbrains.jps.model.artifact.elements.JpsCompositePackagingElement)3 THashSet (gnu.trove.THashSet)2 JpsAndroidModuleExtension (org.jetbrains.jps.android.model.JpsAndroidModuleExtension)2 JpsElement (org.jetbrains.jps.model.JpsElement)2 JpsPackagingElement (org.jetbrains.jps.model.artifact.elements.JpsPackagingElement)2 JpsLibrary (org.jetbrains.jps.model.library.JpsLibrary)2 BuildFileProperty (com.intellij.lang.ant.config.impl.BuildFileProperty)1 SmartList (com.intellij.util.SmartList)1 HashMap (com.intellij.util.containers.HashMap)1 HashSet (com.intellij.util.containers.HashSet)1 MultiMap (com.intellij.util.containers.MultiMap)1 TIntObjectHashMap (gnu.trove.TIntObjectHashMap)1