-
Notifications
You must be signed in to change notification settings - Fork 314
/
Copy pathAarLibrary.java
73 lines (68 loc) · 3.1 KB
/
AarLibrary.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
* Copyright 2018 The Bazel Authors. All rights reserved.
*
* 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 com.google.idea.blaze.android.sync.model;
import com.google.idea.blaze.android.libraries.UnpackedAars;
import com.google.idea.blaze.base.ideinfo.ArtifactLocation;
import com.google.idea.blaze.base.ideinfo.LibraryArtifact;
import com.google.idea.blaze.base.model.BlazeLibrary;
import com.google.idea.blaze.base.model.LibraryKey;
import com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.OrderRootType;
import com.intellij.openapi.roots.libraries.Library.ModifiableModel;
import java.io.File;
import javax.annotation.concurrent.Immutable;
/**
* A library corresponding to an AAR file. Has jars and resource directories.
*
* <p>We may want {@link com.google.idea.blaze.java.libraries.BlazeSourceJarNavigationPolicy} to
* work with these library jars too. However, aar_import will need to have an attribute to point at
* any source jars corresponding to jars within the aar.
*/
@Immutable
public final class AarLibrary extends BlazeLibrary {
private static final long serialVersionUID = 1L;
private static final Logger logger = Logger.getInstance(AarLibrary.class);
public final LibraryArtifact libraryArtifact;
public final ArtifactLocation aarArtifact;
public AarLibrary(LibraryArtifact libraryArtifact, ArtifactLocation aarArtifact) {
// Use the aar's name for the library key. The jar name is the same for all AARs, so could more
// easily get a hash collision.
super(LibraryKey.fromArtifactLocation(aarArtifact));
this.libraryArtifact = libraryArtifact;
this.aarArtifact = aarArtifact;
}
/**
* Create an IntelliJ library that matches Android Studio's expectation for an AAR. See {@link
* org.jetbrains.android.facet.ResourceFolderManager#addAarsFromModuleLibraries}.
*/
@Override
public void modifyLibraryModel(
Project project,
ArtifactLocationDecoder artifactLocationDecoder,
ModifiableModel libraryModel) {
UnpackedAars unpackedAars = UnpackedAars.getInstance(project);
File resourceDirectory = unpackedAars.getResourceDirectory(artifactLocationDecoder, this);
File jar = unpackedAars.getClassJar(artifactLocationDecoder, this);
if (resourceDirectory == null) {
logger.warn("Failed to update AAR library model for: " + aarArtifact);
return;
}
libraryModel.addRoot(pathToUrl(jar), OrderRootType.CLASSES);
libraryModel.addRoot(pathToUrl(resourceDirectory), OrderRootType.CLASSES);
}
}