001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.eclipse.aether.impl.scope; 020 021import java.util.Arrays; 022import java.util.Collections; 023import java.util.HashSet; 024import java.util.Objects; 025import java.util.Set; 026 027/** 028 * Set of constants meant to be used in "common builds". 029 * 030 * @since 2.0.0 031 */ 032public final class CommonBuilds { 033 private CommonBuilds() {} 034 035 private abstract static class Label { 036 private final String id; 037 038 protected Label(String id) { 039 this.id = id; 040 } 041 042 public String getId() { 043 return id; 044 } 045 046 @Override 047 public boolean equals(Object o) { 048 if (this == o) { 049 return true; 050 } 051 if (o == null || getClass() != o.getClass()) { 052 return false; 053 } 054 Label label = (Label) o; 055 return Objects.equals(id, label.id); 056 } 057 058 @Override 059 public int hashCode() { 060 return Objects.hash(id); 061 } 062 063 @Override 064 public String toString() { 065 return id; 066 } 067 } 068 069 private static final class ProjectPathImpl extends Label implements ProjectPath { 070 private final int order; 071 private final int reverseOrder; 072 073 private ProjectPathImpl(String id, int order, int reverseOrder) { 074 super(id); 075 this.order = order; 076 this.reverseOrder = reverseOrder; 077 } 078 079 @Override 080 public int order() { 081 return order; 082 } 083 084 @Override 085 public int reverseOrder() { 086 return reverseOrder; 087 } 088 } 089 090 private static final class BuildPathImpl extends Label implements BuildPath { 091 private final boolean reverse; 092 private final int order; 093 094 private BuildPathImpl(String id, boolean reverse, int order) { 095 super(id); 096 this.reverse = reverse; 097 this.order = order; 098 } 099 100 @Override 101 public boolean isReverse() { 102 return reverse; 103 } 104 105 @Override 106 public int order() { 107 return order; 108 } 109 } 110 111 private static final class BuildScopeImpl extends Label implements BuildScope { 112 private final Set<ProjectPath> projectPaths; 113 private final Set<BuildPath> buildPaths; 114 private final int order; 115 116 private BuildScopeImpl(String id, Set<ProjectPath> projectPaths, Set<BuildPath> buildPaths, int order) { 117 super(id); 118 this.projectPaths = projectPaths; 119 this.buildPaths = buildPaths; 120 this.order = order; 121 } 122 123 @Override 124 public Set<ProjectPath> getProjectPaths() { 125 return projectPaths; 126 } 127 128 @Override 129 public Set<BuildPath> getBuildPaths() { 130 return buildPaths; 131 } 132 133 @Override 134 public int order() { 135 return order; 136 } 137 } 138 139 /** 140 * A common "main" project path. 141 */ 142 public static final ProjectPath PROJECT_PATH_MAIN = new ProjectPathImpl("main", 1, 3); 143 144 /** 145 * A common "test" project path. 146 */ 147 public static final ProjectPath PROJECT_PATH_TEST = new ProjectPathImpl("test", 2, 1); 148 149 /** 150 * A common "it" project path. 151 */ 152 public static final ProjectPath PROJECT_PATH_IT = new ProjectPathImpl("it", 3, 2); 153 154 /** 155 * A common "preprocess" build path. 156 */ 157 public static final BuildPath BUILD_PATH_PREPROCESS = new BuildPathImpl("preprocess", false, 1); 158 159 /** 160 * A common "compile" build path. 161 */ 162 public static final BuildPath BUILD_PATH_COMPILE = new BuildPathImpl("compile", false, 2); 163 164 /** 165 * A common "runtime" build path. 166 */ 167 public static final BuildPath BUILD_PATH_RUNTIME = new BuildPathImpl("runtime", true, 3); 168 169 /** 170 * Maven2/Maven3 special build scope: it did not distinguish between "test compile" 171 * and "test runtime", but lumped both together into "test". 172 */ 173 public static final BuildScope MAVEN_TEST_BUILD_SCOPE = new BuildScopeImpl( 174 "test", 175 Collections.singleton(PROJECT_PATH_TEST), 176 Collections.unmodifiableSet(new HashSet<>(Arrays.asList(BUILD_PATH_COMPILE, BUILD_PATH_RUNTIME))), 177 10); 178}