Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: Added configurations to apply constraints to dependencies resolves #134 #159

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions gestalt-android-testbed/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,20 @@ dependencies {

annotationProcessor(project(":gestalt-inject-java"))
}
configurations {
// Apply constraints to enforce specific versions
all {
resolutionStrategy {
force(
"com.android.support:appcompat-v7:28.0.0",
"com.android.support.constraint:constraint-layout:1.1.3",
"com.github.tony19:logback-android:1.3.0-3",
"com.android.support.test:runner:1.0.2",
"com.android.support.test.espresso:espresso-core:3.0.2"
)
}
}
}

// Android projects don't provide direct access to compileJava but this seems to work.
// https://stackoverflow.com/a/42297051
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import java.util.Optional;
import java.util.Set;

import javax.annotation.Nonnull;

/**
* An abstract implementation of AssetDataProducer aimed to ease the creation of producers that provide fragments from other assets.
* <p>
Expand Down Expand Up @@ -71,7 +73,7 @@ public Set<Name> getModulesProviding(Name resourceName) {
return ImmutableSet.copyOf(Collections2.transform(assetManager.resolve(resourceName.toString(), rootAssetType), new Function<ResourceUrn, Name>() {
@Nullable
@Override
public Name apply(ResourceUrn input) {
public Name apply(@Nonnull ResourceUrn input) {
return input.getModuleName();
}
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj instanceof Asset) {
Asset other = (Asset) obj;
if (obj instanceof Asset<?>) {
Asset<?> other = (Asset<?>) obj;
return !urn.isInstance() && !other.urn.isInstance() && other.urn.equals(urn);
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.terasology.gestalt.assets;


import android.support.annotation.Nullable;

import com.google.common.base.Function;
Expand Down Expand Up @@ -45,16 +46,17 @@
import java.lang.ref.ReferenceQueue;
import java.lang.ref.WeakReference;
import java.lang.reflect.Type;
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;


import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.Semaphore;

import javax.annotation.Nonnull;

/**
* AssetType manages all assets of a particular type/class. It provides the ability to resolve and load assets by Urn, and caches assets so that there is only
* a single instance of a given asset shared by all users.
Expand Down Expand Up @@ -131,7 +133,7 @@ public synchronized void close() {
/**
* Disposes any assets queued for disposal. This occurs if an asset is no longer referenced by anything.
*/
@SuppressWarnings("unchecked")
//@SuppressWarnings("unchecked")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can either remove those suppressions or leave them be but commenting them out like that in committed code is rather messy.

public void processDisposal() {
Reference<? extends Asset<U>> ref = disposalQueue.poll();
while (ref != null) {
Expand Down Expand Up @@ -298,7 +300,7 @@ synchronized void registerAsset(Asset<U> asset, DisposalHook disposer) {
}

/**
* Creates and returns an instance of an asset, if possible. The following methods are used to create the copy, in order, with the first technique to succeeed used:
* Creates and returns an instance of an asset, if possible. The following methods are used to create the copy, in order, with the first technique to succeed used:
* <ol>
* <li>Delegate to the parent asset to create the copy</li>
* <li>Loads the AssetData of the parent asset and create a new instance from that</li>
Expand All @@ -307,7 +309,7 @@ synchronized void registerAsset(Asset<U> asset, DisposalHook disposer) {
* @param urn The urn of the asset to create an instance of
* @return An instance of the desired asset
*/
@SuppressWarnings("unchecked")
// @SuppressWarnings("unchecked")
public Optional<T> getInstanceAsset(ResourceUrn urn) {
Optional<? extends T> parentAsset = getAsset(urn.getParentUrn());
if (parentAsset.isPresent()) {
Expand All @@ -328,16 +330,16 @@ Optional<T> createInstance(Asset<U> asset) {
Optional<? extends Asset<U>> result = asset.createCopy(asset.getUrn().getInstanceUrn());
if (!result.isPresent()) {
try {
return AccessController.doPrivileged((PrivilegedExceptionAction<Optional<T>>) () -> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Despite being deprecated, I'm afraid that for the time being we do still need to use the AccessController APIs. Gestalt sandboxes modules using SecurityManager as an additional precaution and until it's completely unusable I'd rather have that safety net than not. The AccessController.doPrivileged calls are needed when running with a SecurityManager active.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then for the requirement I will revert them in the PR.


for (AssetDataProducer<U> producer : producers) {
Optional<U> data = producer.getAssetData(asset.getUrn());
if (data.isPresent()) {
return Optional.of(loadAsset(asset.getUrn().getInstanceUrn(), data.get()));
}
}
return Optional.ofNullable(assetClass.cast(result.get()));
});
} catch (PrivilegedActionException e) {

} catch (Exception e) {
logger.error("Failed to load asset '" + asset.getUrn().getInstanceUrn() + "'", e.getCause());
}
}
Expand All @@ -355,16 +357,16 @@ public Optional<T> reload(ResourceUrn urn) {
Preconditions.checkArgument(!urn.isInstance(), "Cannot reload an asset instance urn");
ResourceUrn redirectUrn = followRedirects(urn);
try {
return AccessController.doPrivileged((PrivilegedExceptionAction<Optional<T>>) () -> {
for (AssetDataProducer<U> producer : producers) {
Optional<U> data = producer.getAssetData(redirectUrn);
if (data.isPresent()) {
return Optional.of(loadAsset(redirectUrn, data.get()));
}
}
return Optional.ofNullable(loadedAssets.get(redirectUrn));
});
} catch (PrivilegedActionException e) {

} catch (Exception e) {
if (redirectUrn.equals(urn)) {
logger.error("Failed to load asset '{}'", redirectUrn, e.getCause());
} else {
Expand Down Expand Up @@ -484,7 +486,7 @@ public Set<ResourceUrn> resolve(String urn, Name moduleContext) {
return Sets.newLinkedHashSet(Collections2.transform(possibleModules, new Function<Name, ResourceUrn>() {
@Nullable
@Override
public ResourceUrn apply(Name input) {
public ResourceUrn apply(@Nonnull Name input) {
return new ResourceUrn(input, resourceName, fragmentName, instance);
}
}));
Expand Down Expand Up @@ -601,7 +603,7 @@ public boolean equals(Object obj) {
return true;
}
if (obj instanceof AssetType) {
AssetType other = (AssetType) obj;
AssetType<?, ?> other = (AssetType<?, ?>) obj;
return assetClass.equals(other.assetClass);
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import javax.tools.FileObject;
import javax.tools.StandardLocation;
import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
Expand All @@ -17,7 +16,7 @@ public class AnnotationTypeWriter {

private final Filer filer;
private final Map<String, HashSet<String>> results = new HashMap<>();
private final Map<String, FileObject> files = new HashMap<>();


public AnnotationTypeWriter(Filer filer) {
this.filer = filer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import javax.tools.FileObject;
import javax.tools.StandardLocation;
import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
Expand All @@ -17,8 +16,7 @@ public class ServiceTypeWriter {

private final Filer filer;
private final Map<String, HashSet<String>> results = new HashMap<>();
private final Map<String, FileObject> files = new HashMap<>();


public ServiceTypeWriter(Filer filer) {
this.filer = filer;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import javax.tools.FileObject;
import javax.tools.StandardLocation;
import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
Expand All @@ -17,7 +16,7 @@ public class SubtypesTypeWriter {

private final Filer filer;
private final Map<String, HashSet<String>> results = new HashMap<>();
private final Map<String, FileObject> files = new HashMap<>();


public SubtypesTypeWriter(Filer filer) {
this.filer = filer;
Expand Down