Search in sources :

Example 1 with JpsArtifact

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

the class MavenEjbArtifactRootCopyingHandlerProvider method createCustomHandler.

@Nullable
@Override
public FileCopyingHandler createCustomHandler(@NotNull JpsArtifact artifact, @NotNull File root, @NotNull JpsPackagingElement contextElement, @NotNull JpsModel model, @NotNull BuildDataPaths buildDataPaths) {
    MavenProjectConfiguration projectConfiguration = JpsMavenExtensionService.getInstance().getMavenProjectConfiguration(buildDataPaths);
    if (projectConfiguration == null)
        return null;
    MavenEjbClientConfiguration ejbCfg = projectConfiguration.ejbClientArtifactConfigs.get(artifact.getName());
    if (ejbCfg == null) {
        JpsArtifact parentArtifact = findParentArtifact(contextElement);
        if (parentArtifact != null) {
            ejbCfg = projectConfiguration.ejbClientArtifactConfigs.get(parentArtifact.getName());
        }
    }
    return ejbCfg == null ? null : new FilterCopyHandler(new MavenResourceFileFilter(root, ejbCfg));
}
Also used : MavenProjectConfiguration(org.jetbrains.jps.maven.model.impl.MavenProjectConfiguration) MavenResourceFileFilter(org.jetbrains.jps.maven.model.impl.MavenResourceFileFilter) FilterCopyHandler(org.jetbrains.jps.incremental.artifacts.instructions.FilterCopyHandler) JpsArtifact(org.jetbrains.jps.model.artifact.JpsArtifact) MavenEjbClientConfiguration(org.jetbrains.jps.maven.model.impl.MavenEjbClientConfiguration) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with JpsArtifact

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

the class JpsPluginSyntheticArtifactProvider method createArtifact.

private static JpsArtifact createArtifact(JpsModule module, JpsPluginModuleProperties properties) {
    JpsPackagingElementFactory factory = JpsPackagingElementFactory.getInstance();
    JpsCompositePackagingElement root = factory.createArtifactRoot();
    String pluginXmlUrl = properties.getPluginXmlUrl();
    if (pluginXmlUrl != null) {
        String pluginXmlPath = JpsPathUtil.urlToPath(pluginXmlUrl);
        JpsCompositePackagingElement metaInfDir = factory.getOrCreateDirectory(root, "META-INF");
        metaInfDir.addChild(factory.createFileCopy(pluginXmlPath, null));
        File pluginXmlFile = JpsPathUtil.urlToFile(pluginXmlUrl);
        if (pluginXmlFile.exists()) {
            try {
                Element rootElement = JDOMUtil.load(pluginXmlFile);
                for (Element dependsElement : JDOMUtil.getChildren(rootElement, "depends")) {
                    String relativePath = dependsElement.getAttributeValue("config-file");
                    if (relativePath != null) {
                        File dependencyFile = new File(pluginXmlFile.getParent(), FileUtil.toSystemDependentName(relativePath));
                        String dependencyPath = FileUtil.toSystemIndependentName(dependencyFile.getAbsolutePath());
                        metaInfDir.addChild(factory.createFileCopy(dependencyPath, null));
                    }
                }
            } catch (JDOMException | IOException e) {
                LOG.info(e);
            }
        }
    }
    JpsJavaDependenciesEnumerator enumerator = JpsJavaExtensionService.dependencies(module).recursively().includedIn(JpsJavaClasspathKind.PRODUCTION_RUNTIME);
    JpsCompositePackagingElement classesDir = factory.getOrCreateDirectory(root, "classes");
    for (JpsModule depModule : enumerator.getModules()) {
        if (depModule.getModuleType().equals(JpsJavaModuleType.INSTANCE)) {
            classesDir.addChild(JpsJavaExtensionService.getInstance().createProductionModuleOutput(depModule.createReference()));
        }
    }
    classesDir.addChild(JpsJavaExtensionService.getInstance().createProductionModuleOutput(module.createReference()));
    for (JpsLibrary library : enumerator.getLibraries()) {
        JpsCompositePackagingElement parent;
        if (hasDirsOnly(library)) {
            parent = classesDir;
        } else {
            parent = factory.getOrCreateDirectory(root, "lib");
        }
        parent.addChild(factory.createLibraryElement(library.createReference()));
    }
    String name = module.getName() + ":plugin";
    JpsArtifact artifact = JpsArtifactService.getInstance().createArtifact(name, root, DirectoryArtifactType.INSTANCE, JpsElementFactory.getInstance().createDummyElement());
    JpsSdk<JpsSimpleElement<JpsIdeaSdkProperties>> sdk = module.getSdk(JpsIdeaSdkType.INSTANCE);
    if (sdk != null) {
        String sandboxHome = sdk.getSdkProperties().getData().getSandboxHome();
        if (sandboxHome != null) {
            artifact.setOutputPath(sandboxHome + "/plugins/" + module.getName());
        }
    }
    return artifact;
}
Also used : JpsCompositePackagingElement(org.jetbrains.jps.model.artifact.elements.JpsCompositePackagingElement) JpsSimpleElement(org.jetbrains.jps.model.JpsSimpleElement) Element(org.jdom.Element) JpsArtifact(org.jetbrains.jps.model.artifact.JpsArtifact) JpsSimpleElement(org.jetbrains.jps.model.JpsSimpleElement) IOException(java.io.IOException) JDOMException(org.jdom.JDOMException) JpsModule(org.jetbrains.jps.model.module.JpsModule) JpsPackagingElementFactory(org.jetbrains.jps.model.artifact.elements.JpsPackagingElementFactory) File(java.io.File) JpsJavaDependenciesEnumerator(org.jetbrains.jps.model.java.JpsJavaDependenciesEnumerator) JpsLibrary(org.jetbrains.jps.model.library.JpsLibrary) JpsCompositePackagingElement(org.jetbrains.jps.model.artifact.elements.JpsCompositePackagingElement)

Example 3 with JpsArtifact

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

the class JpsAntSerializationTest method testLoadArtifactProperties.

public void testLoadArtifactProperties() {
    loadProject(PROJECT_PATH);
    List<JpsArtifact> artifacts = JpsArtifactService.getInstance().getSortedArtifacts(myProject);
    assertEquals(2, artifacts.size());
    JpsArtifact dir = artifacts.get(0);
    assertEquals("dir", dir.getName());
    JpsAntArtifactExtension preprocessing = JpsAntExtensionService.getPreprocessingExtension(dir);
    assertNotNull(preprocessing);
    assertTrue(preprocessing.isEnabled());
    assertEquals(getUrl("build.xml"), preprocessing.getFileUrl());
    assertEquals("show-message", preprocessing.getTargetName());
    assertEquals(JpsAntArtifactExtensionImpl.ARTIFACT_OUTPUT_PATH_PROPERTY, assertOneElement(preprocessing.getAntProperties()).getPropertyName());
    JpsAntArtifactExtension postprocessing = JpsAntExtensionService.getPostprocessingExtension(dir);
    assertNotNull(postprocessing);
    assertEquals(getUrl("build.xml"), postprocessing.getFileUrl());
    assertEquals("create-file", postprocessing.getTargetName());
    List<BuildFileProperty> properties = postprocessing.getAntProperties();
    assertEquals(2, properties.size());
    assertEquals(JpsAntArtifactExtensionImpl.ARTIFACT_OUTPUT_PATH_PROPERTY, properties.get(0).getPropertyName());
    assertEquals(dir.getOutputPath(), properties.get(0).getPropertyValue());
    assertEquals("message.text", properties.get(1).getPropertyName());
    assertEquals("post", properties.get(1).getPropertyValue());
    JpsArtifact jar = artifacts.get(1);
    assertEquals("jar", jar.getName());
    assertNull(JpsAntExtensionService.getPostprocessingExtension(jar));
    assertNull(JpsAntExtensionService.getPreprocessingExtension(jar));
}
Also used : BuildFileProperty(com.intellij.lang.ant.config.impl.BuildFileProperty) JpsArtifact(org.jetbrains.jps.model.artifact.JpsArtifact) JpsAntArtifactExtension(org.jetbrains.jps.ant.model.artifacts.JpsAntArtifactExtension)

Example 4 with JpsArtifact

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

the class ArtifactBuildTarget method computeRootDescriptors.

@NotNull
@Override
public List<ArtifactRootDescriptor> computeRootDescriptors(JpsModel model, ModuleExcludeIndex index, IgnoredFileIndex ignoredFileIndex, BuildDataPaths dataPaths) {
    ArtifactInstructionsBuilderImpl builder = new ArtifactInstructionsBuilderImpl(index, ignoredFileIndex, this, model, dataPaths);
    ArtifactInstructionsBuilderContext context = new ArtifactInstructionsBuilderContextImpl(model, dataPaths);
    final JpsArtifact artifact = getArtifact();
    String outputPath = StringUtil.notNullize(artifact.getOutputPath());
    final CopyToDirectoryInstructionCreator instructionCreator = new CopyToDirectoryInstructionCreator(builder, outputPath);
    LayoutElementBuildersRegistry.getInstance().generateInstructions(artifact, instructionCreator, context);
    return builder.getDescriptors();
}
Also used : JpsArtifact(org.jetbrains.jps.model.artifact.JpsArtifact) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with JpsArtifact

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

the class AndroidJpsUtil method getProGuardConfigIfShouldRun.

public static ProGuardOptions getProGuardConfigIfShouldRun(@NotNull CompileContext context, @NotNull JpsAndroidModuleExtension extension) throws IOException {
    if (extension.isRunProguard()) {
        return new ProGuardOptions(extension.getProguardConfigFiles(extension.getModule()));
    }
    final String cfgPathsStrFromContext = context.getBuilderParameter(AndroidCommonUtils.PROGUARD_CFG_PATHS_OPTION);
    if (cfgPathsStrFromContext != null && cfgPathsStrFromContext.length() > 0) {
        final String[] paths = cfgPathsStrFromContext.split(File.pathSeparator);
        if (paths.length > 0) {
            final File[] files = toFiles(paths);
            return new ProGuardOptions(Arrays.asList(files));
        }
    }
    for (JpsArtifact artifact : getAndroidArtifactsToBuild(context)) {
        final JpsAndroidModuleExtension facetFromArtifact = getPackagedFacet(artifact);
        final JpsModule moduleFromArtifact = facetFromArtifact != null ? facetFromArtifact.getModule() : null;
        if (moduleFromArtifact != null && moduleFromArtifact.equals(extension.getModule())) {
            final JpsElement props = artifact.getProperties();
            if (props instanceof JpsAndroidApplicationArtifactProperties) {
                final JpsAndroidApplicationArtifactProperties androidProps = (JpsAndroidApplicationArtifactProperties) props;
                if (androidProps.isRunProGuard()) {
                    final List<String> cfgFileUrls = androidProps.getProGuardCfgFiles(moduleFromArtifact);
                    final List<File> cfgPaths = cfgFileUrls != null ? urlsToFiles(cfgFileUrls) : null;
                    return new ProGuardOptions(cfgPaths);
                }
            }
        }
    }
    return null;
}
Also used : JpsElement(org.jetbrains.jps.model.JpsElement) JpsArtifact(org.jetbrains.jps.model.artifact.JpsArtifact)

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