Skip to content

Commit 5e242d6

Browse files
committed
java: rework layout
* move ortools/<cmp>/samples/*.java to ortools/<cmp>/samples/java/*.java * move ortools/<cmp/>java/*.java to ortools/java/com/google/ortools/<cmp>/*.java javatests: remove bazel tests for cp/linearsolver and routing until java wrappers is available.
1 parent 7c9e010 commit 5e242d6

194 files changed

Lines changed: 1520 additions & 984 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cmake/java.cmake

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -675,13 +675,9 @@ function(add_java_sample)
675675
message(STATUS "Configuring sample ${SAMPLE_FILE_NAME} ...")
676676

677677
if(NOT SAMPLE_COMPONENT_NAME)
678-
# sample is located in ortools/<component_name>/sample/
679-
get_filename_component(SAMPLE_DIR ${SAMPLE_FILE_NAME} DIRECTORY)
680-
get_filename_component(COMPONENT_DIR ${SAMPLE_DIR} DIRECTORY)
681-
get_filename_component(COMPONENT_NAME ${COMPONENT_DIR} NAME)
682-
else()
683-
set(COMPONENT_NAME ${SAMPLE_COMPONENT_NAME})
678+
message(FATAL_ERROR "no FILE_NAME provided")
684679
endif()
680+
set(COMPONENT_NAME ${SAMPLE_COMPONENT_NAME})
685681
string(REPLACE "_" "" COMPONENT_NAME_LOWER ${COMPONENT_NAME})
686682

687683
set(SAMPLE_DIR ${PROJECT_BINARY_DIR}/java/${COMPONENT_NAME}/${SAMPLE_NAME})

ortools/algorithms/java/CMakeLists.txt

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,3 @@ set_target_properties(jnialgorithms PROPERTIES
2828
SWIG_USE_TARGET_INCLUDE_DIRECTORIES ON
2929
POSITION_INDEPENDENT_CODE ON)
3030
target_link_libraries(jnialgorithms PRIVATE ortools::ortools)
31-
32-
if(BUILD_JAVA_TESTING)
33-
file(GLOB JAVA_SRCS "*Test.java")
34-
foreach(FILE_NAME IN LISTS JAVA_SRCS)
35-
add_java_test(FILE_NAME ${FILE_NAME})
36-
endforeach()
37-
38-
# These tests are too long so we disable them.
39-
set_tests_properties(
40-
java_algorithms_KnapsackSolverTest
41-
PROPERTIES DISABLED TRUE)
42-
endif()

ortools/algorithms/samples/BUILD.bazel

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
# limitations under the License.
1313

1414
load("@rules_cc//cc:cc_test.bzl", "cc_test")
15-
load("@rules_java//java:java_binary.bzl", "java_binary")
1615
load("@rules_python//python:py_test.bzl", "py_test")
17-
load("//tools/testing:bintest.bzl", "bintest")
1816

1917
package(default_visibility = ["//visibility:public"])
2018

@@ -55,19 +53,3 @@ py_test(
5553
main = "knapsack.py",
5654
deps = ["//ortools/algorithms/python:knapsack_solver"],
5755
)
58-
59-
java_binary(
60-
name = "Knapsack",
61-
srcs = ["Knapsack.java"],
62-
main_class = "com.google.ortools.algorithms.samples.Knapsack",
63-
deps = [
64-
"//ortools/algorithms/java:knapsacksolver",
65-
"//ortools/java/com/google/ortools:Loader",
66-
],
67-
)
68-
69-
bintest(
70-
name = "KnapsackTest",
71-
srcs = [":KnapsackTest.bintest"],
72-
named_data = {"Knapsack": ":Knapsack"},
73-
)

ortools/algorithms/samples/CMakeLists.txt

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,11 @@ if(BUILD_PYTHON_SAMPLES)
2929
endforeach()
3030
endif()
3131

32-
if(BUILD_JAVA_SAMPLES)
33-
file(GLOB JAVA_SRCS "*.java")
34-
foreach(SAMPLE IN LISTS JAVA_SRCS)
35-
add_java_sample(FILE_NAME ${SAMPLE})
36-
endforeach()
37-
endif()
38-
3932
if(BUILD_DOTNET_SAMPLES)
4033
file(GLOB DOTNET_SRCS "*.cs")
4134
foreach(SAMPLE IN LISTS DOTNET_SRCS)
4235
add_dotnet_sample(FILE_NAME ${SAMPLE})
4336
endforeach()
4437
endif()
38+
39+
add_subdirectory(java)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Copyright 2010-2025 Google LLC
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
14+
load("@rules_java//java:java_binary.bzl", "java_binary")
15+
load("//tools/testing:bintest.bzl", "bintest")
16+
17+
package(default_visibility = ["//visibility:public"])
18+
19+
java_binary(
20+
name = "Knapsack",
21+
srcs = ["Knapsack.java"],
22+
main_class = "com.google.ortools.algorithms.samples.Knapsack",
23+
deps = [
24+
"//ortools/algorithms/java:knapsacksolver",
25+
"//ortools/java/com/google/ortools:Loader",
26+
],
27+
)
28+
29+
bintest(
30+
name = "KnapsackTest",
31+
srcs = [":KnapsackTest.bintest"],
32+
named_data = {"Knapsack": ":Knapsack"},
33+
)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright 2010-2025 Google LLC
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
14+
if(NOT BUILD_JAVA_SAMPLES)
15+
return()
16+
endif()
17+
18+
file(GLOB JAVA_SRCS "*.java")
19+
foreach(SAMPLE IN LISTS JAVA_SRCS)
20+
add_java_sample(
21+
FILE_NAME ${SAMPLE}
22+
COMPONENT_NAME algorithms
23+
)
24+
endforeach()
File renamed without changes.
File renamed without changes.

ortools/constraint_solver/docs/CP.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ if __name__ == '__main__':
126126
### Java code samples
127127

128128
```java
129-
// Snippet from ortools/constraint_solver/samples/SimpleCpProgram.java
129+
// Snippet from ortools/constraint_solver/samples/java/SimpleCpProgram.java
130130
package com.google.ortools.constraintsolver.samples;
131131
import com.google.ortools.Loader;
132132
import com.google.ortools.constraintsolver.DecisionBuilder;

ortools/constraint_solver/samples/CMakeLists.txt

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,11 @@ if(BUILD_PYTHON_SAMPLES)
2929
endforeach()
3030
endif()
3131

32-
if(BUILD_JAVA_SAMPLES)
33-
file(GLOB JAVA_SRCS "*.java")
34-
foreach(SAMPLE IN LISTS JAVA_SRCS)
35-
add_java_sample(FILE_NAME ${SAMPLE})
36-
endforeach()
37-
endif()
38-
3932
if(BUILD_DOTNET_SAMPLES)
4033
file(GLOB DOTNET_SRCS "*.cs")
4134
foreach(SAMPLE IN LISTS DOTNET_SRCS)
4235
add_dotnet_sample(FILE_NAME ${SAMPLE})
4336
endforeach()
4437
endif()
38+
39+
add_subdirectory(java)

0 commit comments

Comments
 (0)