// Path: maven/src/main/java/com/redhat/ceylon/cmr/maven/AetherRepository.java
// public class AetherRepository extends MavenRepository {
//     private final AetherUtils utils;
// 
//     private AetherRepository(AetherContentStore acs) {
//         super(acs.createRoot());
//         utils = acs.getUtils();
//     }
// 
//     public static CmrRepository createRepository(Logger log, boolean offline, int timeout) {
//         return createRepository(log, null, offline, timeout);
//     }
// 
//     public static CmrRepository createRepository(Logger log, String settingsXml, boolean offline, int timeout) {
//         AetherContentStore acs = new AetherContentStore(log, offline, timeout);
//         AetherRepository repo = new AetherRepository(acs);
//         repo.utils.overrideSettingsXml(settingsXml);
//         return repo;
//     }
// 
//     @Override
//     public String[] getArtifactNames(ArtifactContext context) {
//         String name = context.getName();
//         final int p = name.contains(":") ? name.lastIndexOf(":") : name.lastIndexOf(".");
// 
//         return getArtifactNames(p >= 0 ? name.substring(p + 1) : name, context.getVersion(), context.getSuffixes());
//     }
// 
//     @Override
//     protected String toModuleName(Node node) {
//         ArtifactContext context = ArtifactContext.fromNode(node);
//         if (context != null) {
//             return context.getName();
//         }
//         String moduleName = node.getLabel();
//         Node parent = NodeUtils.firstParent(node);
//         String groupId = NodeUtils.getFullPath(parent, ".");
//         // That's sort of an invariant, but let's be safe
//         if (groupId.startsWith("."))
//             groupId = groupId.substring(1);
//         moduleName = groupId != null ? groupId + ":" + moduleName : moduleName;
//         return moduleName;
//     }
// 
//     @Override
//     protected List<String> getDefaultParentPathInternal(ArtifactContext context) {
//         return MavenRepository.getParentPath(context);
//     }
// 
//     @Override
//     public Node findParent(ArtifactContext context) {
//         if (context.getName().startsWith("ceylon.")) {
//             return null;
//         }
//         return super.findParent(context);
//     }
// 
//     public ArtifactResult getArtifactResultInternal(RepositoryManager manager, Node node) {
//         return utils.findDependencies(manager, node);
//     }
//     
//     @Override
//     public void completeVersions(ModuleVersionQuery lookup, ModuleVersionResult result) {
//         if(lookup.getType() != Type.ALL && lookup.getType() != null){
//             boolean ok = false;
//             for(String suffix : lookup.getType().getSuffixes()){
//                 if(suffix.equals(ArtifactContext.JAR)){
//                     ok = true;
//                     break;
//                 }
//             }
//             if(!ok)
//                 return;
//         }
//         // this means only for explicitly Maven modules that have a ":"
//         if(lookup.getName().indexOf(':') == -1)
//             return;
//         String[] groupArtifactIds = utils.nameToGroupArtifactIds(lookup.getName());
//         if(groupArtifactIds == null)
//             return;
//         // FIXME: does not respect paging or count
//         utils.search(groupArtifactIds[0], groupArtifactIds[1], lookup.getVersion(), result, getOverrides(), getDisplayString());
//     }
// }


import java.io.File;
import java.net.URL;
import com.redhat.ceylon.cmr.api.CmrRepository;
import com.redhat.ceylon.cmr.impl.CMRJULLogger;
import com.redhat.ceylon.cmr.maven.AetherRepository;
import com.redhat.ceylon.common.log.Logger;
/*
 * Copyright 2014 Red Hat inc. and third party contributors as noted
 * by the author tags.
 * 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.redhat.ceylon.test.maven.test;



/**
 * Abstract Aether tests.
 *
 * @author <a href="mailto:ales.justin@jboss.org">Ales Justin</a>
 */
public abstract class AbstractAetherTest {
    protected static final Logger log = new CMRJULLogger();

    protected CmrRepository createAetherRepository() throws Exception {
        URL settingsURL = getClass().getClassLoader().getResource("maven-settings/settings.xml");
        String settingsXml = new File(settingsURL.toURI()).getPath();
// Path: maven/src/main/java/com/redhat/ceylon/cmr/maven/AetherRepository.java
// public class AetherRepository extends MavenRepository {
//     private final AetherUtils utils;
// 
//     private AetherRepository(AetherContentStore acs) {
//         super(acs.createRoot());
//         utils = acs.getUtils();
//     }
// 
//     public static CmrRepository createRepository(Logger log, boolean offline, int timeout) {
//         return createRepository(log, null, offline, timeout);
//     }
// 
//     public static CmrRepository createRepository(Logger log, String settingsXml, boolean offline, int timeout) {
//         AetherContentStore acs = new AetherContentStore(log, offline, timeout);
//         AetherRepository repo = new AetherRepository(acs);
//         repo.utils.overrideSettingsXml(settingsXml);
//         return repo;
//     }
// 
//     @Override
//     public String[] getArtifactNames(ArtifactContext context) {
//         String name = context.getName();
//         final int p = name.contains(":") ? name.lastIndexOf(":") : name.lastIndexOf(".");
// 
//         return getArtifactNames(p >= 0 ? name.substring(p + 1) : name, context.getVersion(), context.getSuffixes());
//     }
// 
//     @Override
//     protected String toModuleName(Node node) {
//         ArtifactContext context = ArtifactContext.fromNode(node);
//         if (context != null) {
//             return context.getName();
//         }
//         String moduleName = node.getLabel();
//         Node parent = NodeUtils.firstParent(node);
//         String groupId = NodeUtils.getFullPath(parent, ".");
//         // That's sort of an invariant, but let's be safe
//         if (groupId.startsWith("."))
//             groupId = groupId.substring(1);
//         moduleName = groupId != null ? groupId + ":" + moduleName : moduleName;
//         return moduleName;
//     }
// 
//     @Override
//     protected List<String> getDefaultParentPathInternal(ArtifactContext context) {
//         return MavenRepository.getParentPath(context);
//     }
// 
//     @Override
//     public Node findParent(ArtifactContext context) {
//         if (context.getName().startsWith("ceylon.")) {
//             return null;
//         }
//         return super.findParent(context);
//     }
// 
//     public ArtifactResult getArtifactResultInternal(RepositoryManager manager, Node node) {
//         return utils.findDependencies(manager, node);
//     }
//     
//     @Override
//     public void completeVersions(ModuleVersionQuery lookup, ModuleVersionResult result) {
//         if(lookup.getType() != Type.ALL && lookup.getType() != null){
//             boolean ok = false;
//             for(String suffix : lookup.getType().getSuffixes()){
//                 if(suffix.equals(ArtifactContext.JAR)){
//                     ok = true;
//                     break;
//                 }
//             }
//             if(!ok)
//                 return;
//         }
//         // this means only for explicitly Maven modules that have a ":"
//         if(lookup.getName().indexOf(':') == -1)
//             return;
//         String[] groupArtifactIds = utils.nameToGroupArtifactIds(lookup.getName());
//         if(groupArtifactIds == null)
//             return;
//         // FIXME: does not respect paging or count
//         utils.search(groupArtifactIds[0], groupArtifactIds[1], lookup.getVersion(), result, getOverrides(), getDisplayString());
//     }
// }


// Path: maven/src/test/java/com/redhat/ceylon/test/maven/test/AbstractAetherTest.java
import java.io.File;
import java.net.URL;
import com.redhat.ceylon.cmr.api.CmrRepository;
import com.redhat.ceylon.cmr.impl.CMRJULLogger;
import com.redhat.ceylon.cmr.maven.AetherRepository;
import com.redhat.ceylon.common.log.Logger;

/*
 * Copyright 2014 Red Hat inc. and third party contributors as noted
 * by the author tags.
 * 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.redhat.ceylon.test.maven.test;



/**
 * Abstract Aether tests.
 *
 * @author <a href="mailto:ales.justin@jboss.org">Ales Justin</a>
 */
public abstract class AbstractAetherTest {
    protected static final Logger log = new CMRJULLogger();

    protected CmrRepository createAetherRepository() throws Exception {
        URL settingsURL = getClass().getClassLoader().getResource("maven-settings/settings.xml");
        String settingsXml = new File(settingsURL.toURI()).getPath();
        return AetherRepository.createRepository(log, settingsXml, false, 60000);