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 3 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 @@ -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.NonNull;
import android.support.annotation.Nullable;

import com.google.common.base.Function;
Expand Down Expand Up @@ -45,9 +46,9 @@
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.security.PrivilegedActionException; //should i even remove these???(not sure)
//import java.security.PrivilegedExceptionAction;
import java.util.Collections;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -131,7 +132,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")
public void processDisposal() {
Reference<? extends Asset<U>> ref = disposalQueue.poll();
while (ref != null) {
Expand Down Expand Up @@ -298,7 +299,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:
Thedrogon marked this conversation as resolved.
Show resolved Hide resolved
* <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 +308,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 +329,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>>) () -> {

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 +356,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 +485,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 +602,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