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 1 commit
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
55 changes: 35 additions & 20 deletions gestalt-android-testbed/build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
plugins {
id("com.android.application")
id("project-report")
Thedrogon marked this conversation as resolved.
Show resolved Hide resolved
id 'com.android.application'
id 'project-report'
}

android {
Expand All @@ -16,8 +16,8 @@ android {
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
packagingOptions {
merge "META-INF/annotations/*"
Expand All @@ -34,30 +34,45 @@ android {
}

dependencies {
implementation(fileTree(dir: "libs", include: ["*.jar"]))
implementation("com.android.support:appcompat-v7:28.0.0")
implementation("com.android.support.constraint:constraint-layout:1.1.3")
implementation(project(":gestalt-android"))
implementation(project(":gestalt-asset-core"))
implementation(project(":gestalt-entity-system"))
implementation(libs.guava)
implementation(libs.slf4j.api)
implementation("com.github.tony19:logback-android:1.3.0-3")
implementation(project(":testpack:testpack-api"))
testImplementation(libs.junit)
androidTestImplementation("com.android.support.test:runner:1.0.2")
androidTestImplementation("com.android.support.test.espresso:espresso-core:3.0.2")
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:appcompat-v7:28.0.0"
implementation "com.android.support.constraint:constraint-layout:1.1.3"
implementation project(":gestalt-android")
implementation project(":gestalt-asset-core")
implementation project(":gestalt-entity-system")
implementation libs.guava
implementation libs.slf4j.api
implementation "com.github.tony19:logback-android:1.3.0-3"
implementation project(":testpack:testpack-api")
testImplementation libs.junit
androidTestImplementation "com.android.support.test:runner:1.0.2"
androidTestImplementation "com.android.support.test.espresso:espresso-core:3.0.2"

annotationProcessor(project(":gestalt-inject-java"))
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
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
// Adds Resources as parameter for AnnotationProcessor (gather ResourceIndex,
// also add resource as input for compilejava, for re-gathering ResourceIndex, when resource was changed.
// also add resource as input for compileJava, for re-gathering ResourceIndex, when resource was changed.
inputs.files android.sourceSets.main.resources.srcDirs
options.compilerArgs = ["-Aresource=${android.sourceSets.main.resources.srcDirs.join(File.pathSeparator)}"]
options.compilerArgs.add("-Aresource=${android.sourceSets.main.resources.srcDirs.join(File.pathSeparator)}")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ protected AbstractFragmentDataProducer(AssetManager assetManager, Class<U> rootA
public Set<Name> getModulesProviding(Name resourceName) {
if (resolveModuleFromRoot) {
return ImmutableSet.copyOf(Collections2.transform(assetManager.resolve(resourceName.toString(), rootAssetType), new Function<ResourceUrn, Name>() {
@SuppressWarnings("null")
Thedrogon marked this conversation as resolved.
Show resolved Hide resolved
@Nullable
@Override
public Name apply(ResourceUrn input) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ public boolean equals(Object obj) {
return true;
}
if (obj instanceof Asset) {
@SuppressWarnings("rawtypes")
Thedrogon marked this conversation as resolved.
Show resolved Hide resolved
Asset other = (Asset) obj;
return !urn.isInstance() && !other.urn.isInstance() && other.urn.equals(urn);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
import java.lang.ref.ReferenceQueue;
import java.lang.ref.WeakReference;
import java.lang.reflect.Type;
import java.security.AccessController;
import java.security.AccessController; // marked for removal(deprecated)
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.Collections;
Expand All @@ -55,6 +55,8 @@
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 All @@ -67,6 +69,8 @@
*/
@API
@ThreadSafe
@SuppressWarnings({ "unchecked", "removal" })
Thedrogon marked this conversation as resolved.
Show resolved Hide resolved

public final class AssetType<T extends Asset<U>, U extends AssetData> implements Closeable {

private static final Logger logger = LoggerFactory.getLogger(AssetType.class);
Expand Down Expand Up @@ -101,7 +105,6 @@ public final class AssetType<T extends Asset<U>, U extends AssetData> implements
* @param assetClass The class of asset this AssetType will manage.
* @param factory The factory used to convert AssetData to Assets for this type
*/
@SuppressWarnings("unchecked")
public AssetType(Class<T> assetClass, AssetFactory<T, U> factory) {
Preconditions.checkNotNull(assetClass);
Preconditions.checkNotNull(factory);
Expand Down Expand Up @@ -131,7 +134,6 @@ public synchronized void close() {
/**
* Disposes any assets queued for disposal. This occurs if an asset is no longer referenced by anything.
*/
@SuppressWarnings("unchecked")
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:
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 +309,6 @@ 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")
public Optional<T> getInstanceAsset(ResourceUrn urn) {
Optional<? extends T> parentAsset = getAsset(urn.getParentUrn());
if (parentAsset.isPresent()) {
Expand All @@ -323,6 +324,8 @@ public Optional<T> getInstanceAsset(ResourceUrn urn) {
* @param asset The asset to create an instance of
* @return The new instance, or {@link Optional#empty} if it could not be created
*/

@SuppressWarnings({ "deprecation" })
Optional<T> createInstance(Asset<U> asset) {
Preconditions.checkArgument(assetClass.isAssignableFrom(asset.getClass()));
Optional<? extends Asset<U>> result = asset.createCopy(asset.getUrn().getInstanceUrn());
Expand Down Expand Up @@ -351,6 +354,7 @@ Optional<T> createInstance(Asset<U> asset) {
* @param urn The urn of the resource to reload.
* @return The asset if it exists (regardless of whether it was reloaded or not)
*/
@SuppressWarnings({ "deprecation" })
public Optional<T> reload(ResourceUrn urn) {
Preconditions.checkArgument(!urn.isInstance(), "Cannot reload an asset instance urn");
ResourceUrn redirectUrn = followRedirects(urn);
Expand Down Expand Up @@ -484,7 +488,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,6 +605,7 @@ public boolean equals(Object obj) {
return true;
}
if (obj instanceof AssetType) {
@SuppressWarnings("rawtypes")
AssetType other = (AssetType) obj;
return assetClass.equals(other.assetClass);
}
Expand Down