Search in sources :

Example 1 with GradleVersion

use of com.android.ide.common.repository.GradleVersion in project android by JetBrains.

the class AndroidGradleJavaProjectModelModifier method findNewExternalDependency.

@Nullable
private static ArtifactDependencySpec findNewExternalDependency(@NotNull Library library, @NotNull AndroidModuleModel androidModel) {
    GradleVersion modelVersion = androidModel.getModelVersion();
    JavaLibrary matchedLibrary = null;
    for (BaseArtifact testArtifact : androidModel.getTestArtifactsInSelectedVariant()) {
        matchedLibrary = findMatchedLibrary(library, testArtifact, modelVersion);
        if (matchedLibrary != null) {
            break;
        }
    }
    if (matchedLibrary == null) {
        Variant selectedVariant = androidModel.getSelectedVariant();
        matchedLibrary = findMatchedLibrary(library, selectedVariant.getMainArtifact(), modelVersion);
    }
    if (matchedLibrary == null) {
        return null;
    }
    // TODO use getRequestedCoordinates once the interface is fixed.
    MavenCoordinates coordinates = matchedLibrary.getResolvedCoordinates();
    if (coordinates == null) {
        return null;
    }
    return new ArtifactDependencySpec(coordinates.getArtifactId(), coordinates.getGroupId(), coordinates.getVersion());
}
Also used : GradleVersion(com.android.ide.common.repository.GradleVersion) ArtifactDependencySpec(com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencySpec) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with GradleVersion

use of com.android.ide.common.repository.GradleVersion in project android by JetBrains.

the class AndroidContentEntriesSetup method addGeneratedSourceFolders.

private void addGeneratedSourceFolders(@NotNull BaseArtifact artifact, @NotNull List<ContentEntry> contentEntries, boolean isTest) {
    JpsModuleSourceRootType sourceType = getSourceType(isTest);
    GradleVersion modelVersion = myAndroidModel.getModelVersion();
    if (artifact instanceof AndroidArtifact || (modelVersion != null && modelVersion.compareIgnoringQualifiers("1.2") >= 0)) {
        // getGeneratedSourceFolders used to be in AndroidArtifact only.
        Collection<File> generatedSourceFolders = getGeneratedSourceFolders(artifact);
        //noinspection ConstantConditions - this returned null in 1.2
        if (generatedSourceFolders != null) {
            addSourceFolders(generatedSourceFolders, contentEntries, sourceType, true);
        }
    }
    if (artifact instanceof AndroidArtifact) {
        sourceType = getResourceSourceType(isTest);
        AndroidArtifact androidArtifact = (AndroidArtifact) artifact;
        addSourceFolders(androidArtifact.getGeneratedResourceFolders(), contentEntries, sourceType, true);
    }
}
Also used : JpsModuleSourceRootType(org.jetbrains.jps.model.module.JpsModuleSourceRootType) GradleVersion(com.android.ide.common.repository.GradleVersion) File(java.io.File)

Example 3 with GradleVersion

use of com.android.ide.common.repository.GradleVersion in project android by JetBrains.

the class EncodingValidationStrategy method validate.

@Override
void validate(@NotNull Module module, @NotNull AndroidModuleModel androidModel) {
    GradleVersion modelVersion = (androidModel.getModelVersion());
    if (modelVersion != null) {
        boolean isOneDotTwoOrNewer = modelVersion.compareIgnoringQualifiers(myOneDotTwoPluginVersion) >= 0;
        // Verify that the encoding in the model is the same as the encoding in the IDE's project settings.
        Charset modelEncoding = null;
        if (isOneDotTwoOrNewer) {
            try {
                AndroidProject androidProject = androidModel.getAndroidProject();
                modelEncoding = Charset.forName(androidProject.getJavaCompileOptions().getEncoding());
            } catch (UnsupportedCharsetException ignore) {
            // It's not going to happen.
            }
        }
        if (myMismatchingEncoding == null && modelEncoding != null && myProjectEncoding.compareTo(modelEncoding) != 0) {
            myMismatchingEncoding = modelEncoding.displayName();
        }
    }
}
Also used : UnsupportedCharsetException(java.nio.charset.UnsupportedCharsetException) Charset(java.nio.charset.Charset) AndroidProject(com.android.builder.model.AndroidProject) GradleVersion(com.android.ide.common.repository.GradleVersion)

Example 4 with GradleVersion

use of com.android.ide.common.repository.GradleVersion in project android by JetBrains.

the class GradleSignStep method _init.

@Override
public void _init() {
    myAndroidModel = AndroidModuleModel.get(myWizard.getFacet());
    PropertiesComponent properties = PropertiesComponent.getInstance(myWizard.getProject());
    String lastSelectedBuildType = properties.getValue(PROPERTY_BUILD_TYPE);
    myBuildTypeComboModel.removeAllElements();
    Set<String> buildTypes = myAndroidModel == null ? Collections.<String>emptySet() : myAndroidModel.getBuildTypes();
    for (String buildType : buildTypes) {
        myBuildTypeComboModel.addElement(buildType);
        if ((lastSelectedBuildType == null && buildType.equals("release")) || buildType.equals(lastSelectedBuildType)) {
            myBuildTypeComboModel.setSelectedItem(buildType);
        }
    }
    myFlavorsListModel.clear();
    List<String> productFlavors;
    if (myAndroidModel == null || myAndroidModel.getProductFlavors().isEmpty()) {
        productFlavors = Collections.emptyList();
    } else {
        // if there are multiple flavors, we want the merged flavor list
        Set<String> mergedFlavors = Sets.newHashSet();
        for (Variant v : myAndroidModel.getAndroidProject().getVariants()) {
            mergedFlavors.add(ExportSignedPackageWizard.getMergedFlavorName(v));
        }
        productFlavors = Lists.newArrayList(mergedFlavors);
        Collections.sort(productFlavors);
    }
    TIntArrayList lastSelectedIndices = new TIntArrayList(productFlavors.size());
    String[] flavors = properties.getValues(PROPERTY_FLAVORS);
    Set<String> lastSelectedFlavors = flavors == null ? Collections.<String>emptySet() : Sets.newHashSet(flavors);
    for (int i = 0; i < productFlavors.size(); i++) {
        String flavor = productFlavors.get(i);
        myFlavorsListModel.addElement(flavor);
        if (lastSelectedFlavors.contains(flavor)) {
            lastSelectedIndices.add(i);
        }
    }
    myFlavorsList.setSelectedIndices(lastSelectedIndices.toNativeArray());
    String lastApkFolderPath = properties.getValue(PROPERTY_APK_PATH);
    File lastApkFolder;
    if (lastApkFolderPath != null) {
        lastApkFolder = new File(lastApkFolderPath);
    } else {
        if (myAndroidModel == null) {
            lastApkFolder = VfsUtilCore.virtualToIoFile(myWizard.getProject().getBaseDir());
        } else {
            lastApkFolder = myAndroidModel.getRootDirPath();
        }
    }
    myApkPathField.setText(lastApkFolder.getAbsolutePath());
    FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
    myApkPathField.addBrowseFolderListener("Select APK Destination Folder", null, myWizard.getProject(), descriptor);
    GradleVersion modelVersion = null;
    if (myAndroidModel != null) {
        modelVersion = myAndroidModel.getModelVersion();
    }
    boolean enabled = modelVersion != null && modelVersion.compareIgnoringQualifiers(MIN_SIGNATURE_SELECTION_VERSION) >= 0;
    myV1JarSignatureCheckBox.setEnabled(enabled);
    myV1JarSignatureCheckBox.setSelected(properties.getBoolean(PROPERTY_V1_SIGN));
    myV2FullAPKSignatureCheckBox.setEnabled(enabled);
    myV2FullAPKSignatureCheckBox.setSelected(properties.getBoolean(PROPERTY_V2_SIGN));
    // Set HTML label here; the visual editor does not like the "&nbsp;" part so set the text here.
    mySignatureHelpLabel.setText("<html><a href=\"\">Signature&nbsp;Help</a></html>");
    mySignatureHelpLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    mySignatureHelpLabel.addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            if (Desktop.isDesktopSupported()) {
                Desktop desktop = Desktop.getDesktop();
                if (desktop.isSupported(Desktop.Action.BROWSE)) {
                    URI uri;
                    try {
                        uri = new URI("http://developer.android.com/about/versions/nougat/android-7.0.html#apk_signature_v2");
                    } catch (URISyntaxException ex) {
                        throw new AssertionError(ex);
                    }
                    try {
                        desktop.browse(uri);
                    } catch (IOException ex) {
                        LOG.error("Failed to open URI '" + uri + "'", ex);
                    }
                }
            }
        }
    });
}
Also used : MouseEvent(java.awt.event.MouseEvent) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) MouseAdapter(java.awt.event.MouseAdapter) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) URI(java.net.URI) TIntArrayList(gnu.trove.TIntArrayList) Variant(com.android.builder.model.Variant) GradleVersion(com.android.ide.common.repository.GradleVersion) PropertiesComponent(com.intellij.ide.util.PropertiesComponent) File(java.io.File)

Example 5 with GradleVersion

use of com.android.ide.common.repository.GradleVersion in project android by JetBrains.

the class BuildSignedApkTest method openAndSignUsingV1Only.

@Test
public void openAndSignUsingV1Only() throws IOException {
    GradleVersion latestVersion = GradleVersion.parse(SdkConstants.GRADLE_PLUGIN_LATEST_VERSION);
    assume().that(latestVersion.compareIgnoringQualifiers(GradleSignStep.MIN_SIGNATURE_SELECTION_VERSION)).isAtLeast(0);
    File jksFile = new File(myTemporaryFolder.getRoot(), "jks");
    File dstFolder = myTemporaryFolder.newFolder("dst");
    guiTest.importSimpleApplication().openFromMenu(BuildSignedApkDialogKeystoreStepFixture::find, "Build", "Generate Signed APK...").createNew().keyStorePath(jksFile.getAbsolutePath()).password("passwd").passwordConfirm("passwd").alias("key").keyPassword("passwd2").keyPasswordConfirm("passwd2").validity("3").firstAndLastName("Android Studio").organizationalUnit("Android").organization("Google").cityOrLocality("Mountain View").stateOrProvince("California").countryCode("US").clickOk().keyStorePassword("passwd").keyAlias("key").keyPassword("passwd2").clickNext().apkDestinationFolder(dstFolder.getAbsolutePath()).setV1SignatureEnabled(true).setV2SignatureEnabled(false).clickFinish();
    // We should verify that a V2 signature is not present, but that is hard to do here.
    File[] apks = dstFolder.listFiles();
    assertThat(apks).hasLength(1);
    File apk = apks[0];
    try (ZipFile zf = new ZipFile(apk)) {
        assertThat(zf.getEntry("META-INF/CERT.SF")).isNotNull();
    }
}
Also used : ZipFile(java.util.zip.ZipFile) GradleVersion(com.android.ide.common.repository.GradleVersion) File(java.io.File) ZipFile(java.util.zip.ZipFile) Test(org.junit.Test)

Aggregations

GradleVersion (com.android.ide.common.repository.GradleVersion)77 File (java.io.File)25 Test (org.junit.Test)16 Module (com.intellij.openapi.module.Module)12 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)11 Nullable (org.jetbrains.annotations.Nullable)10 Project (com.intellij.openapi.project.Project)6 NotNull (org.jetbrains.annotations.NotNull)6 ArtifactDependencyModel (com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel)5 IOException (java.io.IOException)5 AndroidPluginInfo (com.android.tools.idea.gradle.plugin.AndroidPluginInfo)4 FixAndroidGradlePluginVersionHyperlink (com.android.tools.idea.gradle.project.sync.hyperlink.FixAndroidGradlePluginVersionHyperlink)3 NotificationHyperlink (com.android.tools.idea.gradle.project.sync.hyperlink.NotificationHyperlink)3 SyncMessage (com.android.tools.idea.gradle.project.sync.messages.SyncMessage)3 ZipFile (java.util.zip.ZipFile)3 VisibleForTesting (com.android.annotations.VisibleForTesting)2 Variant (com.android.builder.model.Variant)2 IDevice (com.android.ddmlib.IDevice)2 Revision (com.android.repository.Revision)2 GradleBuildModel (com.android.tools.idea.gradle.dsl.model.GradleBuildModel)2