Skip to content

Draft: Implement a basic artifact attributes API #14

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

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ tasks.withType(JavaCompile).configureEach {
tasks.register('transformJar', JarTransformationTask) {
addTransformer('net/minecraftforge/artifactural/gradle/GradleRepositoryAdapter') {
it.methods.find {
it.name == '<init>' && it.desc == '(Lnet/minecraftforge/artifactural/api/repository/Repository;Lorg/gradle/api/internal/artifacts/repositories/DefaultMavenLocalArtifactRepository;)V'
it.name == '<init>' && it.desc == '(Lorg/gradle/api/artifacts/ConfigurationContainer;Lnet/minecraftforge/artifactural/api/repository/Repository;Lorg/gradle/api/internal/artifacts/repositories/DefaultMavenLocalArtifactRepository;)V'
}?.tap {
it.instructions.find {
it instanceof InsnNode && it.opcode == Opcodes.ACONST_NULL
Expand Down Expand Up @@ -258,6 +258,6 @@ publishing {
}
}

changelog {
from '3.0'
}
//changelog {
// from '3.0'
//}
2 changes: 1 addition & 1 deletion header.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Artifactural
Copyright (c) 2018-2021.
Copy link
Member

Choose a reason for hiding this comment

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

Wow this hasn't been built in quite some time.
We've moved to the SPDX header format in modern projects for this exact reason.
Having times in the header isn't necessary anymore.
https://github.com/MinecraftForge/InstallerTools/blob/master/LICENSE-header.txt

Copyright (c) 2018-2024.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Artifactural
* Copyright (c) 2018-2021.
* Copyright (c) 2018-2024.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand All @@ -19,13 +19,13 @@

package net.minecraftforge.artifactural.api.artifact;

import net.minecraftforge.artifactural.api.cache.ArtifactCache;
import net.minecraftforge.artifactural.api.transform.ArtifactTransformer;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;

import net.minecraftforge.artifactural.api.cache.ArtifactCache;
import net.minecraftforge.artifactural.api.transform.ArtifactTransformer;

public interface Artifact {

static Artifact none() {
Expand All @@ -48,6 +48,10 @@ default Artifact.Cached optionallyCache(ArtifactCache cache) {
return this instanceof Artifact.Cached ? (Artifact.Cached) this : cache(cache);
}

default ArtifactAttributeCollection getAttributes() {
return getIdentifier().getAttributes();
}

boolean isPresent();

InputStream openStream() throws IOException, MissingArtifactException;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Artifactural
* Copyright (c) 2018-2024.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

package net.minecraftforge.artifactural.api.artifact;

public interface ArtifactAttribute<T> {
static <T> ArtifactAttribute<T> create(String name, Class<T> type) {
return new SimpleArtifactAttribute<>(name, type);
}

String getName();

Class<T> getType();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Artifactural
* Copyright (c) 2018-2024.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

package net.minecraftforge.artifactural.api.artifact;

import java.util.Map.Entry;
import java.util.Set;

public interface ArtifactAttributeCollection extends Iterable<Entry<ArtifactAttribute<?>, Object>> {
static ArtifactAttributeCollection empty() {
return Internal.NO_ATTRIBUTES;
}

<T> T with(ArtifactAttribute<T> attribute, T value);

<T> T get(ArtifactAttribute<T> key);

Set<ArtifactAttribute<?>> keys();
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Artifactural
* Copyright (c) 2018-2021.
* Copyright (c) 2018-2024.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -37,6 +37,8 @@ static ArtifactIdentifier none() {

String getExtension();

ArtifactAttributeCollection getAttributes();

static Predicate<ArtifactIdentifier> groupMatches(String group) {
return identifier -> identifier.getGroup().matches(group);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Artifactural
* Copyright (c) 2018-2021.
* Copyright (c) 2018-2024.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Artifactural
* Copyright (c) 2018-2021.
* Copyright (c) 2018-2024.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Artifactural
* Copyright (c) 2018-2021.
* Copyright (c) 2018-2024.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand All @@ -21,12 +21,39 @@

import java.io.File;
import java.io.InputStream;
import java.util.Collections;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import net.minecraftforge.artifactural.api.cache.ArtifactCache;
import net.minecraftforge.artifactural.api.transform.ArtifactTransformer;

final class Internal {

static final ArtifactAttributeCollection NO_ATTRIBUTES = new ArtifactAttributeCollection() {
@Override
public <T> T with(ArtifactAttribute<T> attribute, T value) {
throw new UnsupportedOperationException();
}

@Override
public <T> T get(ArtifactAttribute<T> key) {
return null;
}

@Override
public Set<ArtifactAttribute<?>> keys() {
return Collections.emptySet();
}

@Override
public Iterator<Entry<ArtifactAttribute<?>, Object>> iterator() {
return Collections.<Entry<ArtifactAttribute<?>, Object>>emptyList().iterator();
}
};

static final ArtifactIdentifier NO_IDENTIFIER = new ArtifactIdentifier() {

@Override
Expand Down Expand Up @@ -59,6 +86,10 @@ public String toString() {
return "NO_IDENTIFIER";
}

@Override
public ArtifactAttributeCollection getAttributes() {
return NO_ATTRIBUTES;
}
};

static final Artifact NO_ARTIFACT = new Artifact.Cached() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Artifactural
* Copyright (c) 2018-2021.
* Copyright (c) 2018-2024.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Artifactural
* Copyright (c) 2018-2024.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

package net.minecraftforge.artifactural.api.artifact;

final class SimpleArtifactAttribute<T> implements ArtifactAttribute<T> {
private final String name;
private final Class<T> type;

public SimpleArtifactAttribute(final String name, final Class<T> type) {
this.name = name;
this.type = type;
}

@Override
public String getName() {
return name;
}

@Override
public Class<T> getType() {
return type;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Artifactural
* Copyright (c) 2018-2021.
* Copyright (c) 2018-2024.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Artifactural
* Copyright (c) 2018-2021.
* Copyright (c) 2018-2024.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Artifactural
* Copyright (c) 2018-2021.
* Copyright (c) 2018-2024.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Artifactural
* Copyright (c) 2018-2021.
* Copyright (c) 2018-2024.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Artifactural
* Copyright (c) 2018-2021.
* Copyright (c) 2018-2024.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Artifactural
* Copyright (c) 2018-2021.
* Copyright (c) 2018-2024.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Artifactural
* Copyright (c) 2018-2021.
* Copyright (c) 2018-2024.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Artifactural
* Copyright (c) 2018-2024.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

package net.minecraftforge.artifactural.gradle;

import net.minecraftforge.artifactural.api.artifact.ArtifactAttribute;
import net.minecraftforge.artifactural.base.artifact.SimpleAttributeCollection;
import org.gradle.api.attributes.Attribute;
import org.gradle.api.attributes.AttributeContainer;

public class GradleAttributeCollection extends SimpleAttributeCollection {
public GradleAttributeCollection(final AttributeContainer container) {
for (Attribute<?> attribute : container.keySet()) {
values.put(ArtifactAttribute.create(attribute.getName(), attribute.getType()), container.getAttribute(attribute));
}
}
}
Loading