// Path: core/src/main/java/com/spotify/missinglink/datamodel/Artifact.java
// @AutoMatter
// public interface Artifact {
// 
//   /** "Name" of artifact, for example a directory path or jar file or something else symbolic. */
//   ArtifactName name();
// 
//   /** Map of classname to class object. Names are com/foo/bar/Baz. Returned map is immutable. */
//   Map<ClassTypeDescriptor, DeclaredClass> classes();
// }


import com.spotify.missinglink.datamodel.Artifact;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
/*-
 * -\-\-
 * missinglink-core
 * --
 * Copyright (C) 2016 - 2021 Spotify AB
 * --
 * 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.
 * -/-/-
 */

/*
 * Copyright (c) 2015 Spotify AB
 *
 * 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.spotify.missinglink;


public class ClassLoadingUtil {

  private static final ArtifactLoader artifactLoader = new ArtifactLoader();
  private static final AtomicReference<List<Artifact>> bootstrapArtifacts = new AtomicReference<>();

  public static FileInputStream findClass(Class<?> aClass) throws Exception {
    final String name = aClass.getName().replace('.', '/') + ".class";
    final File outputDir = FilePathHelper.getPath("target/test-classes");
    List<File> files =
        Files.walk(outputDir.toPath())
            .map(Path::toFile)
            .filter(file -> file.isFile() && file.getAbsolutePath().endsWith(name))
// Path: core/src/main/java/com/spotify/missinglink/datamodel/Artifact.java
// @AutoMatter
// public interface Artifact {
// 
//   /** "Name" of artifact, for example a directory path or jar file or something else symbolic. */
//   ArtifactName name();
// 
//   /** Map of classname to class object. Names are com/foo/bar/Baz. Returned map is immutable. */
//   Map<ClassTypeDescriptor, DeclaredClass> classes();
// }


// Path: core/src/test/java/com/spotify/missinglink/ClassLoadingUtil.java
import com.spotify.missinglink.datamodel.Artifact;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

/*-
 * -\-\-
 * missinglink-core
 * --
 * Copyright (C) 2016 - 2021 Spotify AB
 * --
 * 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.
 * -/-/-
 */

/*
 * Copyright (c) 2015 Spotify AB
 *
 * 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.spotify.missinglink;


public class ClassLoadingUtil {

  private static final ArtifactLoader artifactLoader = new ArtifactLoader();
  private static final AtomicReference<List<Artifact>> bootstrapArtifacts = new AtomicReference<>();

  public static FileInputStream findClass(Class<?> aClass) throws Exception {
    final String name = aClass.getName().replace('.', '/') + ".class";
    final File outputDir = FilePathHelper.getPath("target/test-classes");
    List<File> files =
        Files.walk(outputDir.toPath())
            .map(Path::toFile)
            .filter(file -> file.isFile() && file.getAbsolutePath().endsWith(name))
            .collect(Collectors.toList());